Last active
September 24, 2021 07:40
-
-
Save masahirompp/4dc521f60d75d1020288093e1fc6f76a to your computer and use it in GitHub Desktop.
Pure JavaScript JST Time
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// どの環境で実行しても、JST時刻を取得する | |
const timeZoneOffset = 9 // JST | |
const getJstDate = () => { | |
const time = Date.now() // UTC millisecond | |
const date = new Date(time) // local date | |
const utcHours = date.getUTCHours() // UTC Hour | |
date.setHours(utcHours + timeZoneOffset) // UTC Hour + TimeZone Offset | |
return { | |
time, | |
tzYear: date.getFullYear(), | |
tzMonth: date.getMonth() + 1, | |
tzDate: date.getDate(), | |
tzDay: date.getDay() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment