简体   繁体   中英

How to convert time from English to French format using JavaScript

I want to convert this:

04/01/2021 02:06:22 PM

to:

04/01/2021 14:06:22

I tried many things but not success, thank you for your help

Use the toLocaleString() method to change time formatting to 24 hours, eg date.toLocaleString('en-US', {hour12: false}) . The toLocaleString method returns a string that represents the date and time according to the provided locale and options parameters.

 const date = new Date(); console.log( date.toLocaleString('en-US', { hour12: false, }), );

try this:

date.toLocaleString("fr");

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