Reputation: 165
I want to create Start and End Time stamp using Moment.js (EST):
I have used moment.js and created like this
var time = new Date();
var startTime=Date.parse(moment(time).startOf('day').tz('America/New_York').format("MM/DD/YYYY HH:mm:ss"));
var endTime=Date.parse(moment(time).tz('America/New_York').format("MM/DD/YYYY HH:mm:ss"));
It is giving time in milliseconds.
Is it correct or wrong?
I am not getting data from db because there is mismatch in Time stamp.
Upvotes: 2
Views: 4704
Reputation: 13662
First thing first, when you use momentjs, STOP using Date
explictly:
var moment = require('moment-timezone');
// moment() without parameter means the current time
// toDate() converts the moment object to a javascript Date
var startTime = moment().tz('America/New_York').startOf('day').toDate();
var endTime = moment().tz('America/New_York').toDate();
// startTime and endTime are Date objects
console.log(startTime);
console.log(endTime);
Upvotes: 7