Home >Web Front-end >JS Tutorial >How Can I Convert UTC Date-Time to Local Browser Time in JavaScript?
Problem:
When receiving a date-time value in UTC format from a server, such as "6/29/2011 4:52:48 PM," it becomes necessary to convert it to the user's local browser time zone using JavaScript.
Solution Using JavaScript:
To accomplish this task, append 'UTC' to the date-time string before converting it to a JavaScript Date object:
var date = new Date('6/29/2011 4:52:48 PM UTC');
This will automatically adjust the date-time to the user's local browser time, resulting in the following output when calling date.toString():
"Wed Jun 29 2011 09:52:48 GMT-0700 (PDT)"
The above is the detailed content of How Can I Convert UTC Date-Time to Local Browser Time in JavaScript?. For more information, please follow other related articles on the PHP Chinese website!