對象
你可以透過在物件中指定日期和時間欄位,來建立 Dayjs 物件。
TIP
這需要 ObjectSupport 插件才能正常使用
js
dayjs.extend(objectSupport);
dayjs({ hour: 15, minute: 10 });
dayjs.utc({ y: 2010, M: 3, d: 5, h: 15, m: 10, s: 3, ms: 123 });
dayjs({
year: 2010,
month: 3,
day: 5,
hour: 15,
minute: 10,
second: 3,
millisecond: 123,
});
dayjs({
years: 2010,
months: 3,
date: 5,
hours: 15,
minutes: 10,
seconds: 3,
milliseconds: 123,
});
day
和 date
欄位都代表月份中的日期。
dayjs({})
會返回表示目前時間的 Dayjs 物件。
請注意,與 new Date(year, month, date)
類似,月份的索引從 0 開始計數。