JS tips and tricks: Difference between revisions

From HPCWIKI
Jump to navigation Jump to search
m (Admin moved page JS tims and tricks to JS tips and tricks)
(Phase 1.2: Fix typo tims → tips (copy content to correct title))
Tags: Blanking Reverted
Line 1: Line 1:


== 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> ==
<code>only toLocaleTimeString() may behave differently based on region / location</code>
<syntaxhighlight lang="javascript">
var time = new Date();
time
Thu May 30 2024 11:56:46 GMT+0900 (한국 표준시)
time.toLocaleString('en-US', { hour: 'numeric', minute: 'numeric', hour12: true })
'11:56 AM'
time.toLocaleString('ko-KR', { hour: 'numeric', minute: 'numeric', hour12: true })
'오전 11:56'
time.toLocaleString('ko-KR')
'2024. 5. 30. 오전 11:56:46'
</syntaxhighlight>
== References ==
<references />

Revision as of 14:05, 14 July 2026