How to convert UTC date time into local date time using JavaScript ?
Given an UTC date and the task is to convert UTC date time into local date-time using JavaScript toLocaleString() function.
Syntax:
Hey geek! The constant emerging technologies in the world of web development always keeps the excitement for this subject through the roof. But before you tackle the big projects, we suggest you start by learning the basics. Kickstart your web development journey by learning JS concepts with our JavaScript Course. Now at it's lowest price ever!
var theDate = new Date(Date.parse('06/14/2020 4:41:48 PM UTC'))
theDate.toLocaleString()JavaScript code:
// Funcion to convert UTC date-time// to Local date-timefunction myFunction() { var theDate = new Date(Date.parse( '06/14/2020 4:41:48 PM UTC')); document.write("Local date Time: ", theDate.toLocaleString());} |
Example: This example converting UTC date time into local date time using JavaScript.
<!DOCTYPE html><html> <head> <title> How to convert UTC date time into local date time? </title> <style> h1 { color: green; } body { text-align: center; } </style></head> <body> <h1>GeekforGeeks</h1> <p> Click the button to convert UTC date and time to local date and time </p> <p> UTC date and time: 06/14/2020 4:41:48 PM </p> <button onclick="myGeeks()"> Try it </button> <p id="demo"></p> <script> function myGeeks() { var theDate = new Date(Date.parse( '06/14/2020 4:41:48 PM UTC')); document.getElementById("demo") .innerHTML = "Local date Time: " + theDate.toLocaleString(); } </script></body> </html> |
Output:
- Before Clicking the Button:

- After Clicking the Button:


