Reputation: 5003
I need to convert utc timestamp to local time using utc offset in seconds. i had used moment-timezone library. This is my code
var moment = require('moment-timezone');
var timestamp = Date.now();
var IST1 = moment(timestamp).utcOffset('+05:30').format('ddd MMM D Y hh:mm:ss A ')
console.log("IST1 '+05:30' --> ", IST1);
var IST2 = moment(timestamp).utcOffset('+19800').format('ddd MMM D Y hh:mm:ss A ')
console.log("IST2 '+19800' --> ", IST2);
But i got output like this
IST1 '+05:30' --> Mon Jun 19 2017 01:39:23 PM
IST2 '+19800' --> Tue Jun 20 2017 04:29:23 AM
Using '+05:30', i got correct time. But using '+19800' , i got wrong time. What is the actual issue related with this code?
Upvotes: 2
Views: 1692
Reputation: 9096
From Moment docs, it looks like the function utcOffset
takes minutes as params and not seconds.
Try using
var IST2 = moment(timestamp)
.utcOffset('+330')
.format('ddd MMM D Y hh:mm:ss A ')
and it should work.
Upvotes: 1