Search code examples
timetimezonemomentjsgmtangular-moment

How to get time zone using moment format


I need to get the current time zone using moment i have given my code like this

console.log(moment.utc(new Date()).format('Z'),moment.utc(new Date()),'moment')

and got the result like

enter image description here

i would like to get +0530 but now i'm getting +00:00, how can we get that!!


Solution

  • You should simply use moment() instead of moment.utc():

    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().

    This brings us to an interesting feature of Moment.js. UTC mode.

    While in UTC mode, all display methods will display in UTC time instead of local time.

    See also Local vs UTC vs Offset guide.