Need to show AM/PM with MomentJS
14,323
To force the English locale globally, add
moment.locale('en');
to your code.
To configure it for a specific moment
instance, you could also use
moment(value).locale('en').format(/* ... */);
in your function.
Author by
ChristyPiffat
Updated on July 13, 2022Comments
-
ChristyPiffat almost 2 years
I am trying to format some dates using MomentJS. I have no problem until I try to add AM/PM or am/pm. I have the following function and am passing in the time from the results of a Breeze EntityQuery where the time is a System.DateTime as shown:
function datetimeCellRendererFunc(value) { // value = Mon Jun 15 2015 09:00:00 GMT-0500 (Central Daylight Time); return moment(value).format("MM/DD/YYYY h:mm A"); }
Whether I use A or a in the formatting, I still end up with the following:
06/15/2015 9:00 上午
Is there something else I need to add? Thank you in advance!!
-
Marko almost 9 yearsAre you using any localization?
-
ChristyPiffat almost 9 yearsNo. Do you normally need to add it? I did use locale('en') as listed below and it worked.
-
Marko almost 9 yearsI would assume you are using moment with all the localizations, i would suggest you download the moment.js only and you would not need to worry about localizations.
-
-
Matt Johnson-Pint almost 9 yearsFYI - The issue with the default locale not being in English was fixed in the latest 2.10.6 release. Update, and this code is then not required.