Node.js Date.format() API Last Updated : 08 Jan, 2025 Summarize Comments Improve Suggest changes Share Like Article Like Report 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 link.<script src="/https/www.geeksforgeeks.org/path/to/date-and-time.min.js"></script>Syntax:format(dateObj, formatString[, utc])Parameters: This method takes the following arguments as parameters:dateObj: It is the object of the date.formatString: It is the new string format in which date will be shown.Return Value: This method returns formatted date and time.Example 1: index.js // Node.js program to demonstrate the // Date.format() method // Importing module const date = require('date-and-time') // Creating object of current date and time // by using Date() const now = new Date(); // Formatting the date and time // by using date.format() method const value = date.format(now,'YYYY/MM/DD HH:mm:ss'); // Display the result console.log("current date and time : " + value) Run the index.js file using the following command:node index.jsOutput:current date and time : 2021/03/07 12:13:46Example 2: index.js // Node.js program to demonstrate the // Date.format() method // Importing module const date = require('date-and-time') // Formatting the date and time // by using date.format() method const value = date.format((new Date('December 17, 1995 03:24:00')), 'YYYY/MM/DD HH:mm:ss'); // Display the result console.log("date and time : " + value) Run the index.js file using the following command:node index.jsOutput:date and time : 1995/12/17 03:24:00Reference: https://github.com/knowledgecode/date-and-time Comment More infoAdvertise with us Next Article Node.js Date.format() API R rohitprasad3 Follow Improve Article Tags : Web Technologies Node.js NodeJS-API NodeJS date-time Similar Reads Node.js Date.isValid() API The date-and-time.Date.isValid() is a minimalist collection of functions for manipulating JS date and time module which is used to validate the particular date and time with its string format. Required Module: Install the module by npm or used it locally. By using npm.npm install date-and-time --sav 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.compile() API 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. 2 min read 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.preparse() API The date-and-time.Date.preparse() is a minimalist collection of functions for manipulating JS date and time module which is used to pre-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 2 min read Like