How to convert date to another timezone in JavaScript ?

Method 1: Using Intl.DateTimeFormat() and format() Method: The Intl.NumberFormat() method is used to represent numbers in a language-sensitive formatting. It can be used to represent currency or percentages according to the locale specified.
The format() method of this object is used to return a string of the date with the specified locale and formatting options. This will format the date to the timezone required and return a string with the converted date.

Syntax:

usaTime = date.toLocaleString("en-US", {timeZone: "America/New_York"});

Example:



filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
      
<head>
    <title>
        How to convert date to another
        timezone in JavaScript?
    </title>
</head>
  
<body>
    <h1 style="color: green">
        GeeksForGeeks
    </h1>
      
    <b>
        How to convert date to another
        timezone in JavaScript?
    </b>
      
    <p>Check the console for the output</p>
      
    <button onclick="changeTimezone()">
        Change timezone
    </button>
      
    <script type="text/javascript">
      
        function changeTimezone() {
      
            let date = new Date(Date.UTC(2012, 11, 20, 3, 0, 0));
              
            console.log('Given IST datetime: ' + date);
          
            let intlDateObj = new Intl.DateTimeFormat('en-US', {
                timeZone: "America/New_York"
            });
          
            let usaTime = intlDateObj.format(date);
            console.log('USA date: ' + usaTime);
        }
    </script>
</body>
  
</html>

chevron_right


Output:

  • Output:
    output-intl
  • Console Output:
    console-1

Method 2: Using toLocaleString() method: The toLocaleString() method is used to return a string that formats the date according to the locale and options specified. It will convert the date on which the method is used from one timezone to another.

Syntax:

usaTime = date.toLocaleString("en-US", {timeZone: "America/New_York"});

Example:

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
      
<head>
    <title>
        How to convert date to another
        timezone in JavaScript?
    </title>
</head>
  
<body>
    <h1 style="color: green">
        GeeksForGeeks
    </h1>
      
    <b>
        How to convert date to another
        timezone in JavaScript?
    </b>
      
    <p>Check the console for the output</p>
      
    <button onclick="changeTimezone()">
        Change timezone
    </button>
      
    <script type="text/javascript">
      
        function changeTimezone() {
      
            let date = 
                new Date(Date.UTC(2012, 11, 20, 3, 0, 0));
            console.log('Given IST datetime: ' + date);
          
            let usaTime = 
                date.toLocaleString("en-US", {
                    timeZone: "America/New_York" 
                });
            console.log('USA datetime: ' + usaTime);
        }
    </script>
</body>
  
</html>

chevron_right


Output:

  • Output:
    output-tolocale
  • Console Output:
    console-1



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.