-
周WEEK
注意:
周 有两种取值方法:- weeks() 、week()
The week of the year varies depending on which day is the first day of the week (Sunday, Monday, etc), and which week is the first week of the year.
各个国家有不同的取值方法~
For example, in the United States, Sunday is the first day of the week. The week with January 1st in it is the first week of the year.
In France, Monday is the first day of the week, and the week with January 4th is the first week of the year.
比如:
2018-09-02 是个周日 用week()取值为36周,是以-----周日为一周的第一天----统计的 (当前地区时间标准)- isoWeek() 、isoWeeks()
International Organization for Standardization
ISO 国际标准化组织
是以-----周一为一周的第一天----统计的
2018-09-02 是个周日 用 isoWeek()取值为35周
同样赋值set 也一样
- weeks() 、week()
- weeks(Number)、week(Number)
- isoWeeks(Number)、 isoWeeks(Number)
得到的值为第Number的当前星期,
比如。2018-09-27 是星期四 moment().weeks(1) 获取的是第一周的星期四的日期
星期
day()、 weekday() 、 isoWeekday()
moment().isoWeekday(1); // Monday
moment().isoWeekday(7); // Sunday月
month() 、 months() (is deprecated 弃用
)
0~11
天
dayOfYear() 一年当中的第几天
Accepts numbers from 1 to 366. If the range is exceeded, it will bubble up to the years.季度
quarter() moment().quarter(1)年
year()
years()(is deprecated 弃用
)
// year(Number)
moment().year(2017) // moment("2017-09-27T13:30:50.268")
- 毫秒 millisecond()、 milliseconds()
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.
秒 second()、seconds(Number)
Accepts numbers from 0 to 59. If the range is exceeded, it will bubble up to the minutes.分钟 minute() 、minutes()
Accepts numbers from 0 to 59. If the range is exceeded, it will bubble up to the hours.小时 hour() 、hours()
// 时间溢出到下一天 (今天是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.
- 日期
date()
dates()is deprecated 弃用
Accepts numbers from 1 to 31. If the range is exceeded, it will bubble up to the months.
Moment#date is for the date of the month, and Moment#day is for the day of the week.
- 星期
weekday() 0~6
isoWeekday() 1~7
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.
- 天
dayOfYear()
Accepts numbers from 1 to 366. If the range is exceeded, it will bubble up to the years. - 周 属于哪一年
weekYear()
isoWeekYear()
const weekYear = moment('2017-12-31').weekYear() // 2018 周日为一周的第一天
const isoWeekYear = moment('2017-12-31').isoWeekYear() // 2017 周一为一周的第一天
- 周数
weeksInYear() 、moment().isoWeeksInYear(); - 天数
moment().daysInMonth() - 取值
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, 'month': 3});
Object parsing was added in 2.9.0
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")
Units 单位
Units are case insensitive, and support plural and short forms:
· 支持复数或简短形式
year (years, y), month (months, M), date (dates, D), hour (hours, h), minute (minutes, m), second (seconds, s), millisecond (milliseconds, ms).最大值
moment.max(Moment[,Moment...]);
没有参数时,返回当前时间
最小值
moment.min(Moment[,Moment...]);操作
add
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 弃用
开始和结束时间
moment().startOf(String);
moment().endOf(String);本地化
moment().local()偏移量
- moment().valueOf() 毫秒
- moment().unix() 秒
- 数组
moment().toArray();
[ 2018, 8, 27, 16, 35, 49, 754 ]
- isBefore()
- isSame()
- isAfter()
- isBetween()
- 闰年 isLeapYear();