MomentJS has many methods to get/set the date inputs. Get will allow us to read the required input unit and set will allow to modify the input unit. This chapter discusses in detail the get/set methods to be used on the moment.
The following table shows the get/set methods available −
Method | Syntax |
---|---|
Millisecond |
moment().millisecond(Number) moment().millisecond(); moment().milliseconds(Number); moment().milliseconds(); |
Second |
moment().second(Number); moment().second(); moment().seconds(Number); moment().seconds(); |
Minute |
moment().minute(Number); moment().minute(); moment().minutes(Number); moment().minutes(); |
Hour |
moment().date(Number); moment().date(); moment().dates(Number); moment().dates(); |
Day of week |
moment().day(Number|String); moment().day(); moment().days(Number|String); moment().days(); |
Date of Month |
moment().date(Number); moment().date(); moment().dates(Number); moment().dates(); |
Day of year |
moment().dayOfYear(Number); moment().dayOfYear(); |
Week of year |
moment().week(Number); moment().week(); moment().weeks(Number); moment().weeks(); |
Week of year (ISO) |
moment().isoWeek(Number); moment().isoWeek(); moment().isoWeeks(Number); moment().isoWeeks(); |
Month |
moment().month(Number|String); moment().month(); |
Quarter |
moment().quarter(); moment().quarter(Number); moment().quarters(); moment().quarters(Number); |
Year |
moment().year(Number); moment().year(); |
Week year |
moment().weekYear(Number); moment().weekYear(); |
Weeks in year |
moment().weeksInYear(); |
Get |
moment().get('year'); moment().get('month'); moment().get('date'); moment().get('hour'); moment().get('minute'); moment().get('second'); moment().get('millisecond'); |
Set |
moment().set(String, Int); moment().set(Object(String, Int)); |
Maximum |
moment.max(Moment[,Moment...]); moment.max(Moment[]); |
Minimum |
moment.min(Moment[,Moment...]); moment.min(Moment[]); |