Jur*_*enW 2 javascript momentjs
你能帮我格式化一个UTC日期到一个本地语言的文本表示(荷兰语是具体的).
代码
var realDate = moment.utc(birthday);
var now = moment();
birthdayToday = (realDate.month() == now.month() && realDate.date() == now.date());
data.Birthdays.push({
Name: preferredName,
Birthday: birthdayToday ? 'Today!' : realDate.format("MMMM D"),
Path: path,
PhotoUrl: photoUrl,
AccountName: accountName,
BirthdayIsToday: birthdayToday
});
Run Code Online (Sandbox Code Playgroud)
由于行realDate.format("MMMM D"),此当前显示为5月31日,6月6日等.我想要的是31 Mei,6 Juni(荷兰日期).
我没有在文档中看到如何使用本地语言格式的明确示例
任何帮助赞赏!
像这样的东西?
var today = moment()
today.lang('de')
console.debug(today.calendar())
console.debug(moment().calendar())
Run Code Online (Sandbox Code Playgroud)
结果:
Heute um 15:54 Uhr
Today at 3:54 PM
Run Code Online (Sandbox Code Playgroud)
请记住包括moment-with-langs.js而不是简单moment.js.还要记住,它.lang提供了特定于实例的配置,因此您必须调用.lang('de')要在德语中使用的每个时刻实例.
或者,如果您想要全局配置:
moment.lang('de') //<-- call not on the instance, but on the moment function
var today = moment()
console.debug(today.calendar())
console.debug(moment().calendar())
Run Code Online (Sandbox Code Playgroud)
结果:
Heute um 15:54 Uhr
Heute um 15:54 Uhr
Run Code Online (Sandbox Code Playgroud)
全局更改区域设置:
moment.locale('nl');
Run Code Online (Sandbox Code Playgroud)
并确保您还加载了与locales.(min.)js文件的时刻
| 归档时间: |
|
| 查看次数: |
19455 次 |
| 最近记录: |