Thursday, May 23, 2024
 Popular · Latest · Hot · Upcoming
44
rated 0 times [  51] [ 7]  / answers: 1 / hits: 43974  / 11 Years ago, wed, january 15, 2014, 12:00:00

I am trying to adjust a time using a timezone offset and a UTC timestamp.



I am running the following code:



var date = {
utc: '2013-10-16T21:31:51',
offset: -480
}

var returnDate = moment(date.utc).utc().zone(date.offset).format('MM/DD/YYYY h:mm A');


What I am expecting is: 10/16/2013 1:31 PM but I am ending up with 10/17/2013 9:31 AM


More From » date

 Answers
11

Here is what worked for me:



var date = {
utc: '2013-10-16T21:31:51',
offset: 480
}

var returnDate = moment.utc(date.utc).zone(date.offset).format('MM/DD/YYYY h:mm A');


If you noticed, I changed the offset to a positive number. This gave the desired result. If the offset was left at -480 the output was 10/17/2013 5:31 AM.



There is a moment#UTC method that initializes the date as UTC vs. local time.


[#73151] Tuesday, January 14, 2014, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
warren

Total Points: 679
Total Questions: 115
Total Answers: 78

Location: Antigua and Barbuda
Member since Sat, Apr 24, 2021
3 Years ago
;