Moment.js Parsing Creation Data
Last Updated :
27 Jun, 2022
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
Moment.js Parsing parseZone() Function
Moment.js Parsing parseZone() function parses the string provided and keeps the resulting moment in a fixed timezone. Furthermore, this method parses the string but keeps the resulting Moment object in a fixed-offset timezone with the provided offset in the string. Syntax: moment.parseZone() moment.
2 min read
Moment.js Parsing String + Format
Moment.js Parsing String+Format is used when we want to parse a date string through the given format string. The parser will ignore the non-alphanumeric characters of the format. It returns the parsed date as a Moment object. Syntax: moment(String, String, Boolean); Parameters: This method accepts t
1 min read
Moment.js Parse Date Format Plugin
Parse Date Format is a moment.js plugin to can be used to extract a date/time string's format from a given string. This format can then be later used with other Moment methods. Write the below command in the terminal to install Date Format Plugin: npm install moment-parseformat The following are so
1 min read
Moment.js isDate() Function
Given a value to the variable and the task is to check whether a variable is an actual date or not in Moment.js using the isDate() method. To check if a variable is a native js Date object, use moment.isDate() method. Syntax: moment.isDate(obj); Parameter: Object Returns: True or False Installati
2 min read
Moment.js Parsing String + Formats
Moment.js Parsing String + Formats is used when we are not sure of the exact format of an input date string. However, we can specify the possible formats in an array as a parameter for it to try and match. It is the same as String + Format, with the exception that this supports multiple formats. As
2 min read