admin管理员组文章数量:1391925
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);
本文标签: javascriptHow to get today start time and current time of EST using MomentjsStack Overflow
版权声明:本文标题:javascript - How to get today start time and current time of EST using Moment.js - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744596189a2614792.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论