JS tips and tricks

From HPCWIKI
Revision as of 12:04, 30 May 2024 by Admin (talk | contribs) (Created page with " == Display JavaScript datetime in 12 hour AM/PM format<ref>https://stackoverflow.com/questions/8888491/how-do-you-display-javascript-datetime-in-12-hour-am-pm-format</ref> == <syntaxhighlight lang="javascript"> toLocaleTimeString() may behave differently based on region / location var time = new Date(); console.log( time.toLocaleString('en-US', { hour: 'numeric', minute: 'numeric', hour12: true }) ); </syntaxhighlight><code>toLocaleTimeString() may behave differently...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Display JavaScript datetime in 12 hour AM/PM format[1]

toLocaleTimeString() may behave differently based on region / location

var time = new Date();
console.log(
  time.toLocaleString('en-US', { hour: 'numeric', minute: 'numeric', hour12: true })
);

toLocaleTimeString() may behave differently based on region / location

References