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')
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745644708a4637899.html
评论列表(0条)