Folks, I am unable to get the UTC timestamp using the momentjs. Hope someone can point me in the right direction
var start = Date.now(); var utc = moment.utc(start).toDate();
or
var utc = moment.utc().toDate(); Tue Nov 11 2014 13:45:13 GMT-0500 (EST)
Returns the EST timezone I am in, not UTC. How do i get the Javascript Date in UTC?
If I do
var utc= moment.utc(); console.log(utc);
output is
{ _useUTC: true, _isUTC: true, _l: undefined, _i: undefined, _f: undefined, _d: Tue Nov 11 2014 13:43:21 GMT-0500 (EST) }
Thanks
utc(). format('YYYY-MM-DD HH:mm:ss'); var localTime = moment. utc(date). toDate(); localTime = moment(localTime).
utc(Date); By default, moment parses and displays in local time. If you want to parse or display a moment in UTC, you can use moment. utc() instead of moment() .
You can directly call function momentInstance. valueOf(), it will return numeric value of time similar to date. getTime() in native java script.
MomentJs recently announced that the library is now deprecated. This is a big deal for the javascript community who actively downloads moment almost 15 million times a week.
Simplest answer from the comments :
moment.utc().valueOf()
Gives UTC timestamp
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With