I want to create Start and End Time stamp using Moment.js (EST):
- StartTime would be today's start time
- EndTime would be current time.
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.
I want to create Start and End Time stamp using Moment.js (EST):
- StartTime would be today's start time
- EndTime would be current time.
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.
Share Improve this question edited Feb 12, 2016 at 16:16 Marcelo 4,4551 gold badge19 silver badges30 bronze badges asked Feb 12, 2016 at 10:44 PrabuPrabu 1653 silver badges14 bronze badges 3- why not use the Date object? I dont think you need moment for this. What do you trying to do?? – Alon Commented Feb 12, 2016 at 10:47
- if I use Date object it will give current timezone time but I need only EST time zone so I am using moment.js – Prabu Commented Feb 12, 2016 at 10:58
- 2 OK.. this is not reason not use date.. – Alon Commented Feb 12, 2016 at 11:03
1 Answer
Reset to default 7First 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);