VOOZH about

URL: https://www.geeksforgeeks.org/node-js/node-js-date-format-api/

⇱ Node.js Date.format() API - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Node.js Date.format() API

Last Updated : 8 Jan, 2025

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 --save
  • By using CDN link.
<script src="/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:

Run the index.js file using the following command:

node index.js

Output:

current date and time : 2021/03/07 12:13:46

Example 2:

Run the index.js file using the following command:

node index.js

Output:

date and time : 1995/12/17 03:24:00

Reference: https://github.com/knowledgecode/date-and-time

Comment

Explore