From the server I get a datetime variable in this format: 6/29/2011 4:52:48 PM
and it is in UTC time. I want to convert it to the current user’s browser time using JavaScript.
How this can be done using JavaScript or jQuery?
From the server I get a datetime variable in this format: 6/29/2011 4:52:48 PM
and it is in UTC time. I want to convert it to the current user’s browser time using JavaScript.
How this can be done using JavaScript or jQuery?
I wrote a nice little script that takes a UTC epoch and converts it the client system timezone and returns it in d/m/Y H:i:s (like the PHP date function) format:
For me above solutions didn't work.
With IE the UTC date-time conversion to local is little tricky. For me, the date-time from web API is
'2018-02-15T05:37:26.007'
and I wanted to convert as per local timezone so I used below code in JavaScript.To me the simplest seemed using
(i thought the first line could be enough but there are timezones which are off in fractions of hours)
Put this function in your head:
Then generate the following for each date in the body of your page:
To remove the GMT and time zone, change the following line:
A JSON date string (serialized in C#) looks like "2015-10-13T18:58:17".
In angular, (following Hulvej) make a
localdate
filter:Then, display local time like: