Node.js Date.compile() API Last Updated : 27 Jan, 2023 Summarize Comments Improve Suggest changes Share Like Article Like Report The date-and-time.Date.compile() is a minimalist collection of functions for manipulating JS date and time module which is used to compile a format string for the parser. Required Module: Install the module by npm or used it locally. By using npm.npm install date-and-time --saveBy using CDN link.<script src="/https/www.geeksforgeeks.org/path/to/date-and-time.min.js"></script>Syntax: compile(formatString)Parameters: This method takes the format string as the parameter. Return Value: This method returns the formatted string date. Example 1: index.js // Node.js program to demonstrate the // Date.compile() method // Importing http module const date = require('date-and-time') // Creating object of current date and time // by using Date() const now = new Date('07-03-2021'); // Getting pattern for the future use // by using date.compile() method const pattern = date.compile('D/M/YYYY'); // Getting formatted date and time // by using format() method const value = date.format(now,pattern) // Display the result console.log("Formatted date and time : " + value) Run the index.js file using the following command: node index.jsOutput: Formatted date and time : 1/1/1970Example 2: index.js // Node.js program to demonstrate the // Date.compile() method // Importing module const date = require('date-and-time') // Creating object of current date and time // by using Date() const now = new Date('07-03-2021'); // Getting pattern for the future use // by using date.compile() method const pattern = date.compile('M/D/YYYY'); // Parsing the date and time // by using date.parse() method const value = date.parse(now.toLocaleDateString(), pattern); // Display the result console.log("Formatted date and time: " + value) Run the index.js file using the following command: node index.jsOutput: Formatted date and time: Sat Jul 03 2021 00:00:00 GMT+0530 (India Standard Time)Reference: https://github.com/knowledgecode/date-and-time Comment More infoAdvertise with us Next Article Node.js Date.compile() API R rohitprasad3 Follow Improve Article Tags : Web Technologies Node.js NodeJS-API NodeJS date-time Similar Reads Node.js Date.addDays() API The date-and-time.Date.addDays() is a minimalist collection of functions for manipulating JS date and time module which is used to add the extra Days to the existing date and time. Required Module: Install the module by npm or used it locally. By using npm.npm install date-and-time --saveBy using CD 2 min read Node.js Date.parse() API The date-and-time.Date.parse() is a minimalist collection of functions for manipulating JS date and time module which is used to parse the date according to a certain pattern. Required Module: Install the module by npm or used it locally. By using npm.npm install date-and-time --saveBy using CDN lin 2 min read Node.js Date.addYears() API The date-and-time.Date.addYears() is a minimalist collection of functions for manipulating JS date and time module which is used to add the extra years to the existing date and time. Required Module: Install the module by npm or used it locally. By using npm. npm install date-and-time --save By usin 2 min read Node.js Date.addHours() API The date-and-time.Date.addHours() is a minimalist collection of functions for manipulating JS date and time module which is used to add the extra Hours to the existing date and time. Required Module: Install the module by npm or used it locally. By using npm.npm install date-and-time --saveBy using 2 min read Node.js Date.format() API The date-and-time.Date.format() is a minimalist collection of functions for manipulating JS date and time module which is used to format the date according to a certain pattern. Required Module: Install the module by npm or used it locally.By using npm.npm install date-and-time --saveBy using CDN li 2 min read Like