UTC
UTC 新增 .utc
.local
.isUTC
API 來解析或顯示 UTC。
var utc = require('dayjs/plugin/utc')
dayjs.extend(utc)
// default local time
dayjs().format() //2019-03-06T17:11:55+08:00
// UTC mode
dayjs.utc().format() // 2019-03-06T09:11:55Z
// convert local time to UTC time
dayjs().utc().format() // 2019-03-06T09:11:55Z
// While in UTC mode, all display methods will display in UTC time instead of local time.
// And 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().isUTC() // true
dayjs.utc().local().format() //2019-03-06T17:11:55+08:00
dayjs.utc('2018-01-01', 'YYYY-MM-DD') // with CustomParseFormat plugin
預設情況下,Day.js 會解析並顯示當地時間。
如果您想解析或顯示 UTC,您可以使用 dayjs.utc()
取代 dayjs()
。
dayjs.utc(dateType?: string | number | Date | Dayjs, format? string)
dayjs.utc 傳回 UTC 模式中的 Dayjs
物件。
.utc()
使用 UTC 時間 傳回已複製的 Dayjs
物件,並帶有使用 UTC 時間的旗標。
.local()
使用當地時間 傳回已複製的 Dayjs
物件,並帶有使用當地時間的旗標。
.isUTC()
isUTC 模式 傳回一個 boolean
值,表示目前的 Dayjs
物件是否為 UTC 模式。