Javascript: convert UTC Date () object to local timezone

I have a Date() object that contains a UTC date that I need to convert to users local timezone. Does anyone know how I can do this? :-)

+6
javascript date time utc
source share
4 answers

Usually I create a new Date object and use the Date.setUTC* functions to copy the date information.

+4
source share

I am sure that this is done for you automatically.

 >>> d = new Date('Fri, 10 Jun 2011 19:49:23 UTC'); Sat Jun 11 2011 07:49:23 GMT+1200 (New Zealand Standard Time) >>> d.getHours(); 7 
+2
source share

This is an old thread, but just in case someone runs into this problem, here's how I got around this problem.

UTC dates from ASP.Net

In my example, I wanted the ASP.Net service to return dates in a user local time zone, even if the date values ​​were stored in SQL Server in the UTC time zone.

0
source share

I found this for you: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/UTC

Method of use: var x = Date.UTC (yyyy, mangmo, dd, hh, mi, ss, ms); // now x is the timestamp in milliseconds (this is a number, not a Date object) var y = new Date (x); // now y is the Date object that you said you want Date.UTC arguments are as follows:
yyyy - year (e.g. 1984 or 2016 )
mangmo - month distorted (number from 0 to 11 )
dd is the day of the month (this is not distorted, it is the same as on a wristwatch or wall calendar)
hh is the hour of the day (0 to 23)
mi - minutes, ss - seconds, ms - milliseconds (I don’t think I need to explain them)

0
source share

All Articles