Moment.js Strftime Plugin
Moment.js supports a general date format syntax that everyone commonly uses. However, it does not have support for Unix-style strftime which is found in generally many libraries except Javascript. The moment-strftime is a plugin for Moment.js that adds this strftime method to be used with all the other functions.
This package can be installed by using the following command:
npm install moment-strftime
Parameters: This method takes date and time as input.
Return Value: This method returns the date and time in strftime format.
The below examples will demonstrate moment.strftime() method.
Example 1:
Javascript
const moment = require( 'moment-strftime' ); // Using strftime function let date = moment().strftime( "%m/%d/%y %I:%M %p %Z" ); console.log(date) |
Output:
07/28/22 12:02 AM
Example 2:
Javascript
const moment = require( 'moment-strftime' ); // Using strftime function let date = moment().strftime( "%d/%m/%y %I:%M %p %Z" ); console.log(date) |
Output:
28/07/22 12:05 AM
Reference: https://momentjs.com/docs/#/plugins/strftime/
Contact Us