To convert local time to UTC is easy:
var localTime = "2018-02-27 11:00";
moment(localTime).utc().format(); // result: "2018-02-27T09:00:00Z"
However I'm not sure if there is a straightforward way to convert my local time to CET (or other timezone such as EST, WEST)
I know that I can do something like this
moment(localTime).tz("Europe/Berlin").format();
which seems to return what I want but still unsure if thats the correct way or not?
To convert local time to UTC is easy:
var localTime = "2018-02-27 11:00";
moment(localTime).utc().format(); // result: "2018-02-27T09:00:00Z"
However I'm not sure if there is a straightforward way to convert my local time to CET (or other timezone such as EST, WEST)
I know that I can do something like this
moment(localTime).tz("Europe/Berlin").format();
which seems to return what I want but still unsure if thats the correct way or not?
Share Improve this question asked Feb 27, 2018 at 9:55 philomathphilomath 2,2096 gold badges34 silver badges46 bronze badges 3-
Yes, it is the the correct way to convert a moment object to
Europe/Berlin
timezone using moment-timezone. – VincenzoC Commented Feb 27, 2018 at 10:03 - ok so what if I want to convert to EST or WEST? – philomath Commented Feb 27, 2018 at 10:49
- 1 Then you pass whichever time zone identifier you want. (Note that abbreviations are not generally valid identifiers). – Matt Johnson-Pint Commented Feb 27, 2018 at 18:17
1 Answer
Reset to default 4You can use the moment-timezone
since it accounts for daylight saving.
moment(momentTZ().tz("Europe/Berlin")).format();
If you do not mind for daylight saving moment itself is fine.