Moment.js Parsing Special Formats Last Updated : 28 Apr, 2025 Comments Improve Suggest changes Like Article Like Report Moment.js is a JavaScript date library for parsing, validating, manipulating, and formatting dates. In this article, we will learn about the parsing of Special Formats in Moment.js. The ISO-8601 format is used as a standard for parsing the date and time. We can also specify HTML5 constants that can be specified in the HTML5_FMT property when parsing dates directly from the browser input elements. Syntax: moment(String, moment.CUSTOM_FORMAT); Parameters: We can use the following parameters for the special formats parsing: String: It is the DateTime that has to be parsed.CUSTOM_FORMAT: A custom format can be specified here. It can also be specified using the HTML5_FMT when dates have to be directly parsed from the browser input elements. HTML5_FMT property has the following available constants: ConstantFormatInput TypeMONTHYYYY-MM<input type="month" />DATEYYYY-MM-DD<input type="date" />TIMEHH: mm<input type="time" />WEEKGGGG-[W]WW<input type="week" />TIME_SECONDSHH:mm:ss<input type="time" step="1" /> Return Value: This function returns the standard time and duration display. Note: This will not work in the normal Node.js program because it requires the moment.js library to be installed. Moment.js can be installed using the following command: npm install moment The following examples will help to understand the Special Format parsing. Example 1: JavaScript const moment = require("moment"); let special_formats1 = moment("2021-05-07T02:30:45", moment.ISO_8601); console.log(special_formats1); let special_formats2 = moment("2022-09-21", ["YYYY-MM", moment.ISO_8601]); console.log(special_formats2); Output: Moment<2021-05-07T02:30:45+05:30> Moment<2022-09-21T00:00:00+05:30> Example 2: JavaScript const moment = require("moment"); let date1 = moment("2022-06-15T15:00:00", moment.HTML5_FMT.DATETIME_LOCAL_SECONDS); let date2 = moment("2022-W50", moment.HTML5_FMT.WEEK); let date3 = moment("2022-05", moment.HTML5_FMT.MONTH); console.log("Date 1:", date1); console.log("Date 2:", date2); console.log("Date 3:", date3); Output: Date 1: Moment<2022-06-15T15:00:00+05:30> Date 2: Moment<2022-12-12T00:00:00+05:30> Date 3: Moment<2022-05-01T00:00:00+05:30> References: https://momentjs.com/docs/#/parsing/special-formats/ Comment More infoAdvertise with us Next Article Moment.js Parsing Special Formats C chaityavora02 Follow Improve Article Tags : Technical Scripter Web Technologies Node.js Technical Scripter 2022 Moment.js Moment.js-Parse +2 More Similar Reads 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 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 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 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 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 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 Parsing String Moment.js is a date library for JavaScript that parses, validates, manipulates, and formats dates. We can use the moment() function passed with a string to parse dates represented as strings. The moment() function is used to create a moment using a string. Syntax: moment(String) Parameters: It take 1 min read Moment.js Customize AM/PM Parsing AM/PM Parsing is the process of analyzing the string to check for AM or PM. This means we're trying to find out whether the given time in string format is in AM or PM. There are two ways to accomplish this. One is by configuring the updateLocale() method and the other is by parsing AM/PM directly fr 3 min read Moment.js Parsing Creation Data 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 4 min read Moment.js Parsing Validation Date Validation in Moment.js moment#isValid is used to check whether a date is considered or not using Moment.js. This can be checked using moment#parsingFlags which returns an object in its response. Before proceeding, please install the moment.js library using the following command. Moment.js mome 2 min read Like