moment.js

2018-09-27  本文已影响0人  如果你还记得我是小双鱼
  1. weeks(Number)、week(Number)
  2. isoWeeks(Number)、 isoWeeks(Number)
    得到的值为第Number的当前星期,
    比如。2018-09-27 是星期四 moment().weeks(1) 获取的是第一周的星期四的日期
    // year(Number)
      moment().year(2017)  // moment("2017-09-27T13:30:50.268")
    const millisecond = moment().millisecond(1)
    const milliseconds = moment().milliseconds(3)

Accepts numbers from 0 to 999. If the range is exceeded, it will bubble up to the seconds.

      // 时间溢出到下一天 (今天是27号)
      moment().hour(24) // moment("2018-09-28T00:44:07.656")

Accepts numbers from 0 to 23. If the range is exceeded, it will bubble up to the day.

Moment#date is for the date of the month, and Moment#day is for the day of the week.

  const weekday = moment('2017-12-31').weekday()  // 0 星期天
  const isoWeekday = moment('2017-12-31').isoWeekday()  // 7  星期天

Gets or sets the ISO day of the week with 1 being Monday and 7 being Sunday.

  const weekYear = moment('2017-12-31').weekYear()   // 2018 周日为一周的第一天
  const isoWeekYear = moment('2017-12-31').isoWeekYear()    // 2017   周一为一周的第一天
    const all = {
     year: moment().get('year'),
     month: moment().get('month'),
     date: moment().get('date'),
     hour: moment().get('hour'),
     minute: moment().get('minute'),
     second: moment().get('second'),
     millisecond: moment().get('millisecond')
    }
    // { year: 2018,  month: 8,   date: 27,   hour: 14,   minute: 23, second: 12,  millisecond: 815 }
  moment().set('year', 2013);
  moment().set('month', 3);  // April
  moment().set('date', 1);
  moment().set('hour', 13);
  moment().set('minute', 20);
  moment().set('second', 30);
  moment().set('millisecond', 123);
  moment.set('M', 3)   // moment("2018-04-27T14:28:07.125")
  const add = moment().add(1, 'day')
  const addmonth = moment([2018, 0, 31]).add(1, 'M')
  // moment("2018-02-28T00:00:00.000")
const addmonth = moment([2016 0, 31]).add(1, 'M')
  // moment("2016-02-29T00:00:00.000")

moment().add('seconds', 1); deorecated 弃用

  1. moment().valueOf() 毫秒
  2. moment().unix() 秒
  moment().toArray();
  [ 2018, 8, 27, 16, 35, 49, 754 ]

上一篇 下一篇

猜你喜欢

热点阅读