Skip to content

Instantly share code, notes, and snippets.

@vemuruadi
Last active August 10, 2016 13:13
Show Gist options
  • Save vemuruadi/b377d9f8ed226a8e6177465992fee705 to your computer and use it in GitHub Desktop.
Save vemuruadi/b377d9f8ed226a8e6177465992fee705 to your computer and use it in GitHub Desktop.
Handling datetime formatting with moment.js
var moment = require('moment')
/***********************************************************************************************
Code snippet to for new date time by merging date from one datetime, time from another datetime.
***********************************************************************************************/
var date = moment.utc('2016-08-10T11:15:01+00:00')
var time = moment.utc('2016-09-12T12:00:01+00:00')
//format for date only
var f1 = 'YYYY-MM-DD'
//format for time only
var f2 = 'HH:mm:ss'
//Bring date from date, time from time
var newDate = moment.utc(date.format(f1) + time.format(f2), f1 + f2, true).format();
console.log(newDate)
/***********************************************************************************************/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment