Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert local time to CET using momentJs

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?

like image 961
Great Question Avatar asked Oct 16 '25 17:10

Great Question


1 Answers

You 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.

like image 56
Giannis Mp Avatar answered Oct 19 '25 06:10

Giannis Mp



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!