- MomentJS - Examples
- MomentJS - Plugins
- MomentJS - Utilities
- MomentJS - Durations
- MomentJS - Customization
- MomentJS - Internationalization
- MomentJS - Date Queries
- Formatting Date And Time
- Manipulate Date And Time
- MomentJS - Getter/Setter
- MomentJS - Date Validation
- MomentJS - Parsing Date And Time
- MomentJS - Introduction
- MomentJS - Environment Setup
- MomentJS - Overview
- MomentJS - Home
MomentJS Useful Resources
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
MomentJS - Formatting Date and Time
MomentJS provides formats to display date in different ways. There are methods available which tells the time from a given moment, from the current moment, difference between two moments etc. It can display date in JSON format, Array, Object, String etc.
Methods to Format Date and Time
The following table shows a pst of methods available which helps in the displaying/formatting of the date as required.
Method | Syntax |
---|---|
moment().format(); moment().format(String); |
|
moment().fromNow(); moment().fromNow(Boolean); |
|
moment().from (Moment|String|Number|Date|Array); | |
moment().toNow(); moment().toNow(Boolean); |
|
moment().to(Moment|String| Number|Date|Array); moment().to(Moment|String| Number|Date|Array, Boolean); |
|
moment().calendar(); moment().calendar(referenceTime); moment().calendar(referenceTime, formats); |
|
moment().diff(Moment|String| Number|Date|Array); moment().diff(Moment|String| Number|Date|Array, String); moment().diff(Moment|String| Number|Date|Array, String, Boolean); |
|
moment().valueOf(); +moment(); |
|
moment().unix(); |
|
moment().daysInMonth(); |
|
moment().toDate(); |
|
moment().toArray(); |
|
moment().toJSON(); |
|
moment().toISOString(); moment().toISOString(keepOffset); |
|
moment().toObject(); |
|
moment().toString(); |
|
moment().inspect(); |