자바스크립트 Date 함수의 타임존

문자열을 인자로 전달하려면 타임존을 고려해야 한다.

new Date('2021-12-31 23:59:59')
node
Welcome to Node.js v14.0.0.
file /etc/localtime
/etc/localtime: symbolic link to /usr/share/zoneinfo/Asia/Seoul
'2021-12-31 23:59:59'
new Date('2021-12-31 23:59:59')
2021-12-31T14:59:59.000Z
new Date('2021-12-31 23:59:59').toString()
'Fri Dec 31 2021 23:59:59 GMT+0900 (대한민국 표준시)'
2021-12-31T14:59:59.000Z
new Date('2021-12-31 23:59:59').toUTCString()
'Fri, 31 Dec 2021 14:59:59 GMT'
2021-12-31T14:59:59.000Z
export TZ=Asia/Calcutta
new Date('2021-12-31 23:59:59')
2021-12-31T18:29:59.000Z
new Date('2021-12-31 23:59:59').toString()
'Fri Dec 31 2021 23:59:59 GMT+0530 (인도 표준시)'
new Date('2021-12-31 23:59:59').toUTCString()
'Fri, 31 Dec 2021 18:29:59 GMT'
const d = new Date()
undefined
d
2021-09-17T13:23:36.636Z
d.toString()
'Fri Sep 17 2021 22:23:36 GMT+0900 (대한민국 표준시)'
d.toUTCString()
'Fri, 17 Sep 2021 13:23:36 GMT'

--

--

JavaScript Developer, https://afrontend.github.io/

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store