Friday, September 5, 2025
HomeLanguagesJavascriptHow to convert UTC date time into local date time using JavaScript...

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:

var theDate = new Date(Date.parse('DATE_IN_UTC'))
theDate.toLocaleString()

Example 1: This example converts UTC date time into local date time using JavaScript. 

html




<body>
    <h1 style="color:green;">
        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>


Output:

 

Example 2: This example converts today’s UTC date time into local date time using JavaScript. 

HTML




<body>
    <h1 style="color:green;">
        GeekforGeeks
    </h1>
  
    <p>
        Click the button to convert
        UTC date and time to local
        date and time
    </p>
  
    <p id="UTC_DATE">
        UTC date and time:
        06/14/2020 4:41:48 PM
    </p>
  
    <button onclick="myGeeks()">
        Try it
    </button>
  
    <p id="demo"></p>
  
    <script>
        var theDate = new Date().toUTCString();
        document.getElementById("UTC_DATE").innerHTML = "UTC date and time: "
                                                        + theDate
        function myGeeks() {
              
            var theDate = new Date().toLocaleString();
          
            document.getElementById("demo")
                .innerHTML = "Local date Time: "
                + theDate.toLocaleString();
        }
    </script>
</body>


Output:

 

RELATED ARTICLES

Most Popular

Dominic
32269 POSTS0 COMMENTS
Milvus
81 POSTS0 COMMENTS
Nango Kala
6638 POSTS0 COMMENTS
Nicole Veronica
11802 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11866 POSTS0 COMMENTS
Shaida Kate Naidoo
6752 POSTS0 COMMENTS
Ted Musemwa
7027 POSTS0 COMMENTS
Thapelo Manthata
6704 POSTS0 COMMENTS
Umr Jansen
6721 POSTS0 COMMENTS