Moment.js is a date library for JavaScript that parses, validates, manipulates, and formats dates. We can use the creationData() method to get information about the input, format etc of a given moment.
The moment().creationData() function can be used to retrieve the creation data of a given specific moment object.
Syntax:
moment().creationData();
Parameters: It does not take any parameters.
Returns: An object with all the necessary data.
Example 1:
JavaScript
import moment from 'moment';
let day = "2010-02-28 13:40:55"
let date = moment(day);
let data = date.creationData();
console.log(data);
Output:
{
input: '2010-02-28 13:40:55',
format: 'YYYY-MM-DD HH:mm:ss',
locale: Locale {
_calendar: {
sameDay: '[Today at] LT',
nextDay: '[Tomorrow at] LT',
nextWeek: 'dddd [at] LT',
lastDay: '[Yesterday at] LT',
lastWeek: '[Last] dddd [at] LT',
sameElse: 'L'
},
_longDateFormat: {
LTS: 'h:mm:ss A',
LT: 'h:mm A',
L: 'MM/DD/YYYY',
LL: 'MMMM D, YYYY',
LLL: 'MMMM D, YYYY h:mm A',
LLLL: 'dddd, MMMM D, YYYY h:mm A'
},
_invalidDate: 'Invalid date',
ordinal: [Function: ordinal],
_dayOfMonthOrdinalParse: /\d{1,2}(th|st|nd|rd)/,
_relativeTime: {
future: 'in %s',
past: '%s ago',
s: 'a few seconds',
ss: '%d seconds',
m: 'a minute',
mm: '%d minutes',
h: 'an hour',
hh: '%d hours',
d: 'a day',
dd: '%d days',
w: 'a week',
ww: '%d weeks',
M: 'a month',
MM: '%d months',
y: 'a year',
yy: '%d years'
},
_months: [
'January', 'February',
'March', 'April',
'May', 'June',
'July', 'August',
'September', 'October',
'November', 'December'
],
_monthsShort: [
'Jan', 'Feb', 'Mar',
'Apr', 'May', 'Jun',
'Jul', 'Aug', 'Sep',
'Oct', 'Nov', 'Dec'
],
_week: { dow: 0, doy: 6 },
_weekdays: [
'Sunday',
'Monday',
'Tuesday',
'Wednesday',
'Thursday',
'Friday',
'Saturday'
],
_weekdaysMin: [
'Su', 'Mo',
'Tu', 'We',
'Th', 'Fr',
'Sa'
],
_weekdaysShort: [
'Sun', 'Mon',
'Tue', 'Wed',
'Thu', 'Fri',
'Sat'
],
_meridiemParse: /[ap]\.?m?\.?/i,
_eras: [ [Object], [Object] ],
_abbr: 'en',
_config: {
calendar: [Object],
longDateFormat: [Object],
invalidDate: 'Invalid date',
ordinal: [Function: ordinal],
dayOfMonthOrdinalParse: /\d{1,2}(th|st|nd|rd)/,
relativeTime: [Object],
months: [Array],
monthsShort: [Array],
week: [Object],
weekdays: [Array],
weekdaysMin: [Array],
weekdaysShort: [Array],
meridiemParse: /[ap]\.?m?\.?/i,
eras: [Array],
abbr: 'en'
},
_dayOfMonthOrdinalParseLenient: /\d{1,2}(th|st|nd|rd)|\d{1,2}/
},
isUTC: false,
strict: undefined
}
Example 2:
JavaScript
import moment from 'moment';
let obj = { year: 1999, month: 4, day: 21 };
let date = moment(obj);
let data = date.creationData();
console.log(data);
Output:
{
input: { year: 1999, month: 4, day: 21 },
format: undefined,
locale: Locale {
_calendar: {
sameDay: '[Today at] LT',
nextDay: '[Tomorrow at] LT',
nextWeek: 'dddd [at] LT',
lastDay: '[Yesterday at] LT',
lastWeek: '[Last] dddd [at] LT',
sameElse: 'L'
},
_longDateFormat: {
LTS: 'h:mm:ss A',
LT: 'h:mm A',
L: 'MM/DD/YYYY',
LL: 'MMMM D, YYYY',
LLL: 'MMMM D, YYYY h:mm A',
LLLL: 'dddd, MMMM D, YYYY h:mm A'
},
_invalidDate: 'Invalid date',
ordinal: [Function: ordinal],
_dayOfMonthOrdinalParse: /\d{1,2}(th|st|nd|rd)/,
_relativeTime: {
future: 'in %s',
past: '%s ago',
s: 'a few seconds',
ss: '%d seconds',
m: 'a minute',
mm: '%d minutes',
h: 'an hour',
hh: '%d hours',
d: 'a day',
dd: '%d days',
w: 'a week',
ww: '%d weeks',
M: 'a month',
MM: '%d months',
y: 'a year',
yy: '%d years'
},
_months: [
'January', 'February',
'March', 'April',
'May', 'June',
'July', 'August',
'September', 'October',
'November', 'December'
],
_monthsShort: [
'Jan', 'Feb', 'Mar',
'Apr', 'May', 'Jun',
'Jul', 'Aug', 'Sep',
'Oct', 'Nov', 'Dec'
],
_week: { dow: 0, doy: 6 },
_weekdays: [
'Sunday',
'Monday',
'Tuesday',
'Wednesday',
'Thursday',
'Friday',
'Saturday'
],
_weekdaysMin: [
'Su', 'Mo',
'Tu', 'We',
'Th', 'Fr',
'Sa'
],
_weekdaysShort: [
'Sun', 'Mon',
'Tue', 'Wed',
'Thu', 'Fri',
'Sat'
],
_meridiemParse: /[ap]\.?m?\.?/i,
_eras: [ [Object], [Object] ],
_abbr: 'en',
_config: {
calendar: [Object],
longDateFormat: [Object],
invalidDate: 'Invalid date',
ordinal: [Function: ordinal],
dayOfMonthOrdinalParse: /\d{1,2}(th|st|nd|rd)/,
relativeTime: [Object],
months: [Array],
monthsShort: [Array],
week: [Object],
weekdays: [Array],
weekdaysMin: [Array],
weekdaysShort: [Array],
meridiemParse: /[ap]\.?m?\.?/i,
eras: [Array],
abbr: 'en'
},
_dayOfMonthOrdinalParseLenient: /\d{1,2}(th|st|nd|rd)|\d{1,2}/
},
isUTC: false,
strict: undefined
}
Reference: https://momentjs.com/docs/#/parsing/creation-data/
Similar Reads
Moment.js Parsing Date Moment.js is a date library for JavaScript that parses, validates, manipulates, and formats dates. We can use the moment() function passed with an object to parse dates represented as Date object. The moment() function is used to create a moment using a Date object. Syntax: moment( Date ) Parameters
1 min read
Moment.js Parsing Defaults Moment.js is a date library for JavaScript that parses, validates, manipulates, and formats dates. We can use the moment() function by providing only a few parameters and the rest will default to the current day, month, or year and 0 for an hour, minute, second, and millisecond. The moment() functio
1 min read
Moment.js Parsing Array Moment.js is a date library for JavaScript that parses, validates, manipulates, and formats dates. We can pass an array to the moment() function to parse a date represented in the form of an array. The moment() function is used to create a moment using an array. Syntax: moment(Number[]) Parameters:
1 min read
Moment.js Duration Format Plugin The Duration plugin makes it possible to add a lot of formatting options to Moment Durations of the Moment.js JavaScript date library. This will make it possible to describe a duration as required by the user. Write the below command in the terminal to install Duration Format Plugin: npm install mom
1 min read
Moment.js Parsing Moment Clone In this article, we will learn how to clone and parse moment.js objects. Cloning and Parsing Moment.js Objects: All Moment.js objects are parsable and clonable. Cloning a moment could be done, both implicitly and explicitly. Installation: npm install moment  Syntax: moment(Moment); // Moment is a
1 min read