Skip to content

Instantly share code, notes, and snippets.

@masahirompp masahirompp/jstTime.js
Last active Dec 7, 2018

Embed
What would you like to do?
Pure JavaScript JST Time
// どの環境で実行しても、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
You can’t perform that action at this time.