UTC
UTC 添加了 .utc
.local
.isUTC
API 以解析或显示 UTC。
var utc = require("dayjs/plugin/utc");
// import utc from 'dayjs/plugin/utc' // ES 2015
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 dayjs.utc(dateType?: string | number | Date | Dayjs, format? string)
返回 UTC 模式下的 Dayjs
对象。
使用 UTC 时间 .utc()
返回带有使用 UTC 时间标志的克隆 Dayjs
对象。
使用当地时间 .local()
返回带有使用本地时间标志的克隆 Dayjs
对象。
设置 UTC 偏移量 .utcOffset()
返回具有新 UTC 偏移量的克隆 Dayjs
对象。
是否 UTC 模式 .isUTC()
返回 boolean
指示当前 Dayjs
对象是否处于 UTC 模式。