|
| 1 | +/** |
| 2 | + * dayjs 的取值|赋值操作 |
| 3 | + */ |
| 4 | +const dayjs = require('dayjs') |
| 5 | + |
| 6 | +// 获取或设置毫秒 |
| 7 | +console.log(dayjs().millisecond()) |
| 8 | +console.log(dayjs().millisecond(1)) |
| 9 | + |
| 10 | +// 获取或设置秒 |
| 11 | +console.log(dayjs().second()) |
| 12 | +console.log(dayjs().second(1)) |
| 13 | + |
| 14 | +// 获取或设置小时 |
| 15 | +console.log(dayjs().hour()) |
| 16 | +console.log(dayjs().hour(12)) |
| 17 | + |
| 18 | +/** |
| 19 | + * dayjs.date 是该月的日期。 dayjs.day 是星期几 |
| 20 | + */ |
| 21 | + |
| 22 | +// 获取或设置月份里的日期 |
| 23 | +console.log(dayjs().date()) |
| 24 | +console.log(dayjs().date(10)) |
| 25 | + |
| 26 | +// 获取或设置星期几 |
| 27 | +console.log(dayjs().day()) |
| 28 | +console.log(dayjs().day(3)) |
| 29 | + |
| 30 | + |
| 31 | +// 获取或设置月份 |
| 32 | +console.log(dayjs().month()) |
| 33 | +console.log(dayjs().month(0)) |
| 34 | + |
| 35 | +// 获取或设置年份 |
| 36 | +console.log(dayjs().year()) |
| 37 | +console.log(dayjs().year(2023)) |
| 38 | + |
| 39 | + |
| 40 | +// get方法获取 |
| 41 | +console.log(dayjs().get('year')) |
| 42 | +console.log(dayjs().get('month')) |
| 43 | +console.log(dayjs().get('date')) |
| 44 | +console.log(dayjs().get('hour')) |
| 45 | +console.log(dayjs().get('minute')) |
| 46 | +console.log(dayjs().get('second')) |
| 47 | +console.log(dayjs().get('millisecond')) |
| 48 | + |
| 49 | +// set方法设置 |
| 50 | +console.log(dayjs().set('date', 1)) |
| 51 | +console.log(dayjs().set('month', 6)) // 5月 |
| 52 | +console.log(dayjs().set('second', 30)) |
| 53 | +// 支持链式调用 |
| 54 | +console.log(dayjs().set('hour', 8).set('minute', 35).set('second', 15)) |
0 commit comments