Node.js date-and-time Date.transform() Method
The date-and-time.Date.transform() method is used to transform date and time from the existing string format to new string format.
Required Module: Install the module by npm or used it locally.
npm install date-and-time --save
<script src="/path/to/date-and-time.min.js"></script>
Syntax:
const transform(dateString, arg1, arg2[, utc])
Parameters: This API takes the following arguments as parameters.
- dateString: String object of the date.
- arg1: Existing string format.
- arg2: New string format.
Return Value: This method returns a formatter string.
Example 1:
index.js
const date = require( 'date-and-time' )
const now = new Date(07-03-2021);
const value = date.transform(
now.toLocaleDateString(),
'D/M/YYYY' , 'YYYY/M/D' );
console.log( "transformed date and time :- "
+ value)
|
Output:
transformed date and time :- 1970/1/1
Example 2:
index.js
const date = require( 'date-and-time' )
const value = date.transform(
'23:14:05 GMT+0900' ,
'HH:mm:ss [GMT]Z' , 'YYYY/M/D' );
console.log( "transformed date and time :- "
+ value)
|
Output:
transformed date and time :- 1970/1/1
Reference: https://github.com/knowledgecode/date-and-time#transformdatestring-arg1-arg2-utc
Last Updated :
30 Jan, 2023
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...