How To Check System's Time Format In Chrome - 12 Hours Or 24 Hours In JavaScript?
date.toLocaleTimeString does not work in chrome and always return time in 12 hours format. I need to display time on the basis of system's time format.
Solution 1:
Use
var x = date()
// Tue May 15 2012 05:45:40 GMT-0500
They already provide you the datetime with the timezone
OR
To make your life easier, use this
https://momentjs.com/
Solution 2:
Short answer is No you can't get the default time format in the browser, because it relies on the System and on the browser settings, thought JavaScript doesn't have access for such options.
But if you want to manage the time format within your code, you can specify the format by which you wnat to show your Date.
Actually the toLocaleString() have a boolean hour12
option that tells the engine to use or not the 12 hours
format:
console.log(date.toLocaleString('en-US', { hour12: false }));
If you set it to false
it will display the time in 24 hours
format.
Post a Comment for "How To Check System's Time Format In Chrome - 12 Hours Or 24 Hours In JavaScript?"