Search code examples
momentjsmoment-timezone

Moment.js is not showing right time


I'm getting wrong time from momentjs when I pass UTC date time I expect it to convert to 7:30pm in Melbourne

Ex:

var myUTCTime = moment("2020-12-02 09:30:00.0000000 +00:00").utc(); 

Wed Dec 02 2020 09:30:00 GMT+0000

var melbourne = moment("2020-12-02 09:30:00.0000000 +00:00").utc().tz("Australia/Melbourne"); 

Wed Dec 02 2020 20:30:00 GMT+1100  

Expecting Melbourne to be Wed Dec 02 2020 19:30:00 GMT+1000  

7:30 PM (19:30) Melbourne Time = 9:30 AM (9:30) UTC

Following url shows the graph

http://www.timebie.com/timezone/universalmelbourne.php


Solution

  • That's taking Daylight Savings into account (observed in month of December).

    For other dates, it's just fine. I tried May.

    moment("2020-05-02 09:30:00.000 +00:00").utc().toString()
    "Sat May 02 2020 09:30:00 GMT+0000"
    
    moment("2020-05-02 09:30:00.000 +00:00").utc().tz("Australia/Melbourne").toString(); 
    "Sat May 02 2020 19:30:00 GMT+1000"