简体   繁体   English

使用momentjs格式化时间跨度的结束日期

[英]format end date of time span using momentjs

I'm trying to format start and end date of a period. 我正在尝试格式化时段的开始和结束日期。

var fromDateAsString = moment("2015-01-01T00:00").format('??');
var toDateAsString = moment("2015-01-02T00:00").format('??');
console.log(fromDateAsString + ' - ' + toDateAsString);

Expected result (german locale): 预期结果(德语语言环境):

1.01.2015 00:00 Uhr - 1.01.2015 24:00 Uhr

Solution should work for other locales too. 解决方案也应适用于其他语言环境。

My Questions: 我的问题:

  • end date (1/2/15 00:00) should be displayed as 1.01.2015 24:00 结束日期(1/2/15 00:00)应该显示为1.01.2015 24:00
  • is there a "short date with time for current locale" format available? 是否有可用的“在当前区域设置时间短日期”格式?

Moment doesn't currently have support for a 24th hour. Moment当前没有24小时支持。 Midnight is always the 0'th hour at the beginning of the day. 午夜始终是一天开始的第0个小时。

Other than that, you can get the format you're asking about by combining the short-date locale format specifier with the time-locale specifier. 除此之外,您还可以通过组合短期语言环境格式说明符和时间语言环境说明符来获取所需的格式。 For example: 例如:

moment.locale('de');
moment("2015-12-31T13:45").format('l LT') // "31.12.2015 13:45"

This will format correctly in other locales: 这将在其他语言环境中正确格式化:

moment.locale('en');
moment("2015-12-31T13:45").format('l LT') // "12/31/2015 1:45 PM"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM