admin管理员组文章数量:1026373
Im trying to get the EST date using moment.js but it always gives me the local datetime.
var curr_date = moment.tz(new Date(), "America/New_York");
when I execute this mand in console, I don't get the NY time.
Im trying to get the EST date using moment.js but it always gives me the local datetime.
var curr_date = moment.tz(new Date(), "America/New_York");
when I execute this mand in console, I don't get the NY time.
Share Improve this question asked Apr 28, 2016 at 10:49 user1050619user1050619 21k89 gold badges251 silver badges430 bronze badges 6-
It stores a
moment
instance incurr_date
. For me, when I execute this in console, it returns the object correctly. What do you get if you entercurr_date.format("HH:mm")
afterwards? – user3297291 Commented Apr 28, 2016 at 10:59 - I'm in Central Time and it gives the central time instead of EST time – user1050619 Commented Apr 28, 2016 at 11:00
- The alert statement gives me the EST time but when I print in console it gives me the actual time(CST). – user1050619 Commented Apr 28, 2016 at 11:07
- this worked...var curr_date = moment.tz(new Date(), "America/New_York");...curr_date.format() – user1050619 Commented Apr 28, 2016 at 11:19
- 1 the _d object that you are seeing in the console does not reflect the actual value of the date contained in moment. Ignore any properties starting with _. Just pay attention to the result of .format() – Maggie Pint Commented Apr 28, 2016 at 18:46
1 Answer
Reset to default 3I found this post really helpful. Basically, stop using the Date object explicitly.
const moment = require('moment-timezone')
const timeInEST = moment().tz('America/New_York').format('MM/DD/YYYY HH:mm')
Im trying to get the EST date using moment.js but it always gives me the local datetime.
var curr_date = moment.tz(new Date(), "America/New_York");
when I execute this mand in console, I don't get the NY time.
Im trying to get the EST date using moment.js but it always gives me the local datetime.
var curr_date = moment.tz(new Date(), "America/New_York");
when I execute this mand in console, I don't get the NY time.
Share Improve this question asked Apr 28, 2016 at 10:49 user1050619user1050619 21k89 gold badges251 silver badges430 bronze badges 6-
It stores a
moment
instance incurr_date
. For me, when I execute this in console, it returns the object correctly. What do you get if you entercurr_date.format("HH:mm")
afterwards? – user3297291 Commented Apr 28, 2016 at 10:59 - I'm in Central Time and it gives the central time instead of EST time – user1050619 Commented Apr 28, 2016 at 11:00
- The alert statement gives me the EST time but when I print in console it gives me the actual time(CST). – user1050619 Commented Apr 28, 2016 at 11:07
- this worked...var curr_date = moment.tz(new Date(), "America/New_York");...curr_date.format() – user1050619 Commented Apr 28, 2016 at 11:19
- 1 the _d object that you are seeing in the console does not reflect the actual value of the date contained in moment. Ignore any properties starting with _. Just pay attention to the result of .format() – Maggie Pint Commented Apr 28, 2016 at 18:46
1 Answer
Reset to default 3I found this post really helpful. Basically, stop using the Date object explicitly.
const moment = require('moment-timezone')
const timeInEST = moment().tz('America/New_York').format('MM/DD/YYYY HH:mm')
本文标签: javascriptGetting EST date in momentjsStack Overflow
版权声明:本文标题:javascript - Getting EST date in moment.js - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745644706a2160954.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论