Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Need to show AM/PM with MomentJS

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!!

like image 776
ChristyPiffat Avatar asked Aug 10 '15 16:08

ChristyPiffat


People also ask

Why you should not use MomentJS?

However, Moment. js has too many drawbacks compared to modern date and time libraries. Its API is not immutable, it is large and it doesn't support tree shaking. Even the Moment team discourages to use their library in new projects.

Should you still use MomentJS?

Moment. js is a fantastic time & date library with lots of great features and utilities. However, if you are working on a performance sensitive web application, it might cause a huge performance overhead because of its complex APIs and large bundle size. Problems with Moment.


1 Answers

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.

like image 63
Jonathan Chan Avatar answered Oct 06 '22 02:10

Jonathan Chan