UTC
默认情况下,Day.js 以当地时间解析和显示。
¥By default, Day.js parses and displays in local time.
如果要解析或显示 UTC 格式的日期时间,可以使用 dayjs.utc() 而不是 dayjs()。
¥If you want to parse or display a date-time in UTC, you can use dayjs.utc() instead of dayjs().
在 UTC 模式下,所有显示方式都将以 UTC 时间显示,而不是本地时间。
¥While in UTC mode, all display methods will display in UTC time instead of local time.
This requires the
UTC
plugin to work
dayjs.extend(utc)
// default local time
dayjs().format() //2019-03-06T08:00:00+08:00
// UTC mode
dayjs.utc().format() // 2019-03-06T00:00:00Z
此外,在 UTC 模式下,所有 getter 和 setter 将在内部使用 Date#getUTC* 和 Date#setUTC* 方法,而不是 Date#get* 和 Date#set* 方法。
¥Additionally, while in UTC mode, all getters and setters will internally use the Date#getUTC* and Date#setUTC* methods instead of the Date#get* and Date#set* methods.
dayjs.utc().seconds(30).valueOf()// => new Date().setUTCSeconds(30)
dayjs.utc().seconds()// => new Date().getUTCSeconds()
要从 UTC 切换到本地时间,你可以使用 dayjs#utc 或 dayjs#local。
¥To switch from UTC to local time, you can use dayjs#utc or dayjs#local.
