简体   繁体   English

将小时格式化为 24 小时

[英]Format hour to 24h

I've got an hour in a string format like this : 14:00:00.000 I want to convert it in a nicer format : 14h我有一个像这样的字符串格式的小时:14:00:00.000 我想以更好的格式转换它:14h

I try to use react-moment for this, with我尝试为此使用反应时刻,

<Moment format="hh:mm:ss.a">"14:00:00.000"</Moment>

But it doesn't work.但它不起作用。 Any good practice?有什么好的做法吗?

momentjs is no longer recommended for use and is explained in detail in the project status page.不再推荐使用momentjs ,在项目状态页面中有详细说明。

Their recommended alternate is Luxon .他们推荐的替代品是Luxon

To format it like you have specified, simply use the toFormat() method.要按照您指定的方式对其进行格式化,只需使用toFormat()方法。 Included in that link is a list of tokens you can use to help format it to exactly how you'd like it.该链接中包含一个令牌列表,您可以使用它来帮助将其格式化为您想要的确切格式。

This formats it like you have asked - 14h :这就像你问的那样格式化 - 14h

DateTime.now().toFormat("HH'h'")

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

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