使用 moment.js 本地化的短时间字符串

Localized short time string using moment.js

如何从 moment.js 对象获取与当前语言环境相关的时间字符串?

moment().format('HH:mm') 

无论本地化如何,总是得到相同的结果。

我想要使用 shortTime 在 angular 中使用的类似结果:

formatDate(new Date(), 'shortTime'): // HH:mm, resp hh:mm a

您可以简单地使用 format() 文档

中列出的 本地化格式

Because preferred formatting differs based on locale, there are a few tokens that can be used to format a moment based on its locale.

There are upper and lower case variations on the same formats. The lowercase version is intended to be the shortened version of its uppercase counterpart.

这里是一个活生生的例子:

console.log( moment().format('LT') );
moment.locale('it');
console.log( moment().format('LT') );
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.24.0/moment-with-locales.min.js"></script>