How do I get the AM/PM value from a DateTime?
How about:
dateTime.ToString("tt", CultureInfo.InvariantCulture);
How to get am pm from the date time string using moment js
You are using the wrong format tokens when parsing your input. You should use ddd
for an abbreviation of the name of day of the week, DD
for day of the month, MMM
for an abbreviation of the month's name, YYYY
for the year, hh
for the 1-12
hour, mm
for minutes and A
for AM/PM
. See moment(String, String)
docs.
Here is a working live sample:
console.log( moment('Mon 03-Jul-2017, 11:00 AM', 'ddd DD-MMM-YYYY, hh:mm A').format('hh:mm A') );console.log( moment('Mon 03-Jul-2017, 11:00 PM', 'ddd DD-MMM-YYYY, hh:mm A').format('hh:mm A') );
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.18.1/moment.min.js"></script>
How do I get the AM/PM value from a just a Time not a date?
You'll need to convert it into a DateTime or write a custom formatter.
@string.Format("{0:hh:mm:ss tt}", new DateTime().Add(worker.BegginingTime))
Technically speaking TimeSpan doesn't store time of day, but rather duration.
How to get AM/PM from a datetime in PHP
You need to convert it to a UNIX timestamp (using strtotime) and then back into the format you require using the date function.
For example:
$currentDateTime = '08/04/2010 22:15:00';
$newDateTime = date('h:i A', strtotime($currentDateTime));
Convert time to am/pm flutter
You can use the intl library https://pub.dev/packages/intl
and format your DateTime
DateFormat.yMEd().add_jms().format(DateTime.now());
Output:
'Thu, 5/23/2013 10:21:47 AM'
how to get AM/PM from datetime? c#
If you just want the string you can do:
equipBooking.BookedFromDteTme.ToString("tt");
Or for a boolean result use:
bool isPM = (equipBooking.BookedFromDteTme.Hour >= 12);
BTW, you don't need to call TimeOfDay
- you can get the Hour
and Minute
property directly from the DateTime
:
dtStartTimeHour.SelectedItem = equipBooking.BookedFromDteTme.Hour;
dtStartTimeMin.SelectedItem = equipBooking.BookedFromDteTme.Minute;
dtStartTimeAMPM.SelectedItem = equipBooking.BookedFromDteTme.ToString("tt");
Format datetime to HH:MM, AM/PM
How to show time in AM or PM format from TimeOfDay with flutter?
Once you have the time selected, you can format it with new DateFormat.jm()
, which will output, for example, 5:00 PM
. See DateFormat docs for more.
Edit: You could do this a few ways.
One way is to use a function, like this:
String formatTimeOfDay(TimeOfDay tod) {
final now = new DateTime.now();
final dt = DateTime(now.year, now.month, now.day, tod.hour, tod.minute);
final format = DateFormat.jm(); //"6:00 AM"
return format.format(dt);
}
Another way is to use this is in the example provided from the docs:
print(new DateFormat.yMMMd().format(new DateTime.now()));
Related Topics
Build Query String for System.Net.Httpclient Get
How to Download Image from Url
How to Combine Values of Several Lists into One in C#
Casting an Object into the Same Type as an Ienumerable Collection
C#, Access Child Properties from Parent Reference
Itextsharp Pdfptable How to Make a Border Around Entire Table
How to Get Only Date from a Datetime Value in Razor Page
Using Newtonsoft to Deserialize a Date Stamp That Might Consist Only of a Year
How to Download File With ASP.NET on Buttton'S Onclick Event
How to Match Hyphens With Regular Expression
Adding an Incremental Number to Duplicate String
Launch an Application and Send It to Second Monitor
What Is the Purpose of a Question Mark After a Type (For Example: Int Myvariable)
How to Convert English Digits to Arabic Digits
C# Download Big File from Server With Less Memory Consumption
What Regular Expression Would I Use to Remove Everything After the Second Backslash