简体   繁体   中英

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

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.

Their recommended alternate is Luxon .

To format it like you have specified, simply use the toFormat() method. 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 :

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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