UTC
UTC 增加了 .utc .local .isUTC APIs 使用 UTC 模式来解析和展示时间。
var utc = require("dayjs/plugin/utc");
dayjs.extend(utc);
// 默认当地时间
dayjs().format(); //2019-03-06T17:11:55+08:00
// UTC 模式
dayjs.utc().format(); // 2019-03-06T09:11:55Z
// 将本地时间转换成 UTC 时间
dayjs().utc().format(); // 2019-03-06T09:11:55Z
// 在 UTC 模式下,所有的展示方法都将使用 UTC 而不是本地时区
// 所有的 get 和 set 方法也都会使用 Date#getUTC* 和 Date#setUTC* 而不是 Date#get* and Date#set*
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 会把时间解析成本地时间。
Day.js 默认使用用户本地时区来解析和展示时间。 如果想要使用 UTC 模式来解析和展示时间,可以使用 dayjs.utc() 而不是 dayjs()
dayjs.utc dayjs.utc(dateType?: string | number | Date | Dayjs, format? string)
返回一个使用 UTC 模式的 Dayjs 对象。
Use UTC time .utc()
返回一个复制的包含使用 UTC 模式标记的 Dayjs 对象。
Use local time .local()
返回一个复制的包含使用本地时区标记的 Dayjs 对象。
Set UTC offset .utcOffset()
返回一个复制的使用 UTC 模式的 Day.js 对象。
isUTC mode .isUTC()
返回一个 boolean 来展示当前 Day.js 对象是不是在 UTC 模式下。
相关内容
- Calendar 使用Day.js的updateLocale方法配置英文日历,定义了不同日期情况下的格式化字符串,如昨天、今天、明天、上周、下周以及其他情况的日期格式。
- 自定义 Day.js 支持自定义语言配置,用户可创建新语言或更新现有语言,需使用 UpdateLocale 插件。配置包括星期、月份等信息。
- Month Abbreviations 使用Day.js的updateLocale方法配置简体中文月份缩写,设置为对应的中文名称。
- Month Names 月份名称在 Day.js 中通过 Locale#months 数组进行定义。用户可以使用 UpdateLocale 插件自定义月份名称。若需要更高级的占位符处理...
- Relative Time 使用Day.js的updateLocale方法配置英文相对时间,定义了未来和过去日期的前缀/后缀,以及不同时间单位的表达方式。
- Weekday Abbreviations 使用Day.js的updateLocale方法配置英文星期缩写,设置为对应的缩写形式。