简体   繁体   中英

How to know the timezone of a given time and convert it to local time using Momentjs

I want to convert given time to local time. I'm using moment.js I checked their momentjs documentation but didn't help.

I've a date & time which is stored as history.

Suppose give date & time: 2017-03-08T05:04:53.3715179. I want to convert it to local time.

I tried doing this:

moment($(this).find('logTime').text()).utc().format('MMMM Do YYYY, h:mm');

But didn't help. I want to convert this date & time to local date & time.

How do i do that?

What do you mean by local time ? if you are talking about your timezone then just apply the timezone.

if you want UTC time then use utc() method from moment

moment('2017-03-08T05:04:53.3715179').utc().format('MMMM Do YYYY, h:mm');

with the timezone

moment('2017-03-08T05:04:53.3715179').tz(yourTimezone).format('MMMM Do YYYY, h:mm');

example // output - "March 7th 2017, 11:34"

moment('2017-03-08T05:04:53.3715179').tz('Europe/London').format('MMMM Do YYYY, h:mm');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM