需要用 MomentJS 显示 AM/PM

Need to show AM/PM with MomentJS

我正在尝试使用 MomentJS 格式化一些日期。在尝试添加 AM/PM 或 am/pm 之前我没有问题。我有以下函数,并从 Breeze EntityQuery 的结果中传递时间,其中时间是 System.DateTime,如图所示:

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");
}

无论我在格式中使用 A 还是 a,我仍然得到以下结果:

06/15/2015 9:00 上午

还有什么我需要补充的吗?提前致谢!!

要在全球强制使用英语语言环境,请添加

moment.locale('en');

到您的代码。

要为特定的 moment 实例配置它,您还可以使用

moment(value).locale('en').format(/* ... */);

在你的函数中。