I have a datetime string: 2016-03-04 14:35:53
this is in `GMT. I have a countdown on my site which counts down time till in seconds.
Now if the user is not gmt they may already be past the time.
How do I use moment.js and moment time zone to adjust this datetime string to the users timezone?
I have a datetime string: 2016-03-04 14:35:53
this is in `GMT. I have a countdown on my site which counts down time till in seconds.
Now if the user is not gmt they may already be past the time.
How do I use moment.js and moment time zone to adjust this datetime string to the users timezone?
Share Improve this question asked Mar 4, 2016 at 16:10 Ricky BarnettRicky Barnett 1,1704 gold badges15 silver badges34 bronze badges2 Answers
Reset to default 12Code that's being run client side is by default in local time, and then you can convert that into UTC by calling the utc method on the moment constructor. So client side, you can run moment.utc()
to get their current time in UTC (which is the same as GMT) and then perform your comparisons on that object.
Please us to get GMT TimeStamp using moment.js
var moment = require('moment');
dt = moment();
dt.subtract(dt.parseZone().utcOffset(), 'minutes')
console.log(dt.unix());