Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript to convert UTC to local time

Okay, say JSON parse string UTC date as below:

2012-11-29 17:00:34 UTC 

Now if I want to convert this UTC date to my local time, how can I do this?

How do I format it to something else like yyyy-MM-dd HH:mm:ss z?

This date.toString('yyyy-MM-dd HH:mm:ss z'); never work out :/

like image 750
lannyboy Avatar asked Nov 29 '12 09:11

lannyboy


People also ask

How do you convert UTC time to local time?

Examples of how to convert UTC to your local time To convert 18:00 UTC (6:00 p.m.) into your local time, subtract 6 hours, to get 12 noon CST. During daylight saving (summer) time, you would only subtract 5 hours, so 18:00 UTC would convert to 1:00 p.m CDT. Note that the U.S. uses a 12-hour format with a.m. and p.m.

How do you convert UTC time to local time in node JS?

Use the Date() constructor to convert UTC to local time, e.g. new Date(utcDateStr) . Passing a date and time string in ISO 8601 format to the Date() constructor converts the UTC date and time to local time. Copied!

How do I convert date to UTC date?

Answer: Use the toString() Method You can simply use the toString() method to convert UTC or GMT date time to local date time in JavaScript.

Is JavaScript date in UTC?

The Date. UTC() method in JavaScript is used to return the number of milliseconds in a Date object since January 1, 1970, 00:00:00, universal time. The UTC() method differs from the Date constructor in two ways: Date.


Video Answer


1 Answers

Try:

var date = new Date('2012-11-29 17:00:34 UTC'); date.toString(); 
like image 124
ajtrichards Avatar answered Sep 21 '22 06:09

ajtrichards