Search This Blog

Friday, September 28, 2018

Nodejs code to convert string date to another date format.

Sample nodejs code to convert string date to another format.


date.js

var moment = require('moment');
bar ('1980-08-29', 'YYYY-MM-DD', 'DD/MM/YYYY');    //calling method

function bar(date, currentFormat, requiredFormat )
{
    var date = moment(date,currentFormat);
    var train_date = date.format(requiredFormat);
    console.log(train_date);        // 29/08/1980
    return train_date;
}
exports.bar = bar;



//npm install --save
//node date.js
Post a Comment

Hit Counter


View My Stats