Append 'UTC' to the string before converting it to a date in javascript:

var date = new Date('6/29/2011 4:52:48 PM UTC');
date.toString() // "Wed Jun 29 2011 09:52:48 GMT-0700 (PDT)"
Answer from digitalbath on Stack Overflow
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Date › toLocaleTimeString
Date.prototype.toLocaleTimeString() - JavaScript | MDN
When the method is called many times with the same arguments, it is better to create an Intl.DateTimeFormat object and use its format() method, because a DateTimeFormat object remembers the arguments passed to it and may decide to cache a slice of the database, so future format calls can search for localization strings within a more constrained context. // Depending on timezone, your results will vary const event = new Date("August 19, 1975 23:15:30 GMT+00:00"); console.log(event.toLocaleTimeString("en-US")); // Expected output: "1:15:30 AM" console.log(event.toLocaleTimeString("it-IT")); // Expected output: "01:15:30" console.log(event.toLocaleTimeString("ar-EG")); // Expected output: "١٢:١٥:٣٠ ص"
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Date › getTimezoneOffset
Date.prototype.getTimezoneOffset() - JavaScript | MDN
The getTimezoneOffset() method of Date instances returns the difference, in minutes, between this date as evaluated in the UTC time zone, and the same date as evaluated in the local time zone. const date1 = new Date("August 19, 1975 23:15:30 GMT+07:00"); const date2 = new Date("August 19, 1975 ...
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Date
Date - JavaScript | MDN
A JavaScript date is fundamentally specified as the time in milliseconds that has elapsed since the epoch, which is defined as the midnight at the beginning of January 1, 1970, UTC (equivalent to the UNIX epoch). This timestamp is timezone-agnostic and uniquely defines an instant in history.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Date › toLocaleDateString
Date.prototype.toLocaleDateString() - JavaScript | MDN
Dezember 2012 console.log(event.toLocaleDateString("ar-EG", options)); // Expected output (varies according to local timezone): الخميس، ٢٠ ديسمبر، ٢٠١٢ console.log(event.toLocaleDateString(undefined, options)); // Expected output (varies according to local timezone and default locale): Thursday, December 20, 2012 ... The locales and options parameters customize the behavior of the function and let applications specify the language whose formatting conventions should be used. In implementations that support the Intl.DateTimeFormat API, these parameters correspond exactly to the Intl.DateTimeFormat() constructor's parameters.
🌐
Go Make Things
gomakethings.com › getting-a-date-in-the-current-users-timezone-with-javascript
Getting a date in the current user's timezone with JavaScript | Go Make Things
An API they’re using returns the date as a string in a fixed timezone (in their case, Denver, Colorado, USA), like this… let dateFromAPI = '2025-01-31T11:50:15'; And they wanted to display it as a formatted string in the current user’s local time. JavaScript makes this a lot harder than ...
🌐
Ursahealth
ursahealth.com › new-insights › dates-and-timezones-in-javascript
Working with dates and timezones in JavaScript: a survival guide
May 4, 2021 - > new Date("2020-01-08T19:47:00.000Z") Wed Jan 08 2020 20:47:00 GMT+0100 (Central European Standard Time) > moment("2020-01-08T19:47:00.000Z").format("h:mm a MMM DD, YYYY") // using moment.js "8:47 pm Jan 08, 2020" > format(parseISO("2020-01-08T19:47:00.000Z"), "h:mm a MMM dd, yyyy") // using date-fns "8:47 PM Jan 08, 2020" This is as it should be. The tweet happened at a moment in time, and that moment should be localized for the user. The timezone that Dave Jorgenson happened to be in is not something we really care about, and the timezone of the Twitter data center is definitely not something we care about. JavaScript’s internal representation uses the “universal” UTC time but by the time the date/time is displayed, it has probably been localized per the timezone settings on the user’s computer.
Top answer
1 of 16
969

Background

JavaScript's Date object tracks time in UTC internally, but typically accepts input and produces output in the local time of the computer it's running on. It has very few facilities for working with time in other time zones.

The internal representation of a Date object is a single number - namely timestamp - representing the number of milliseconds that have elapsed since 1970-01-01 00:00:00 UTC, without regard to leap seconds.

There is no time zone or string format stored in the Date object itself.

When various functions of the Date object are used, the computer's local time zone is applied to the internal representation. If the function produces a string, then the computer's locale information may be taken into consideration to determine how to produce that string. The details vary per function, and some are implementation-specific.

The only operations the Date object can do with non-local time zones are:

  • It can parse a string containing a numeric UTC offset from any time zone. It uses this to adjust the value being parsed, and stores the UTC equivalent. The original local time and offset are not retained in the resulting Date object. For example:

      var d = new Date("2020-04-13T00:00:00.000+08:00");
      d.toISOString()  //=> "2020-04-12T16:00:00.000Z"
      d.valueOf()      //=> 1586707200000  (this is what is actually stored in the object)
    
  • In environments that have implemented the ECMASCript Internationalization API (aka "Intl"), a Date object can produce a locale-specific string adjusted to a given time zone identifier. This is accomplished via the timeZone option to toLocaleString and its variations. Most implementations will support IANA time zone identifiers, such as 'America/New_York'. For example:

      var d = new Date("2020-04-13T00:00:00.000+08:00");
      d.toLocaleString('en-US', { timeZone: 'America/New_York' })
      //=> "4/12/2020, 12:00:00 PM"
      // (midnight in China on April 13th is noon in New York on April 12th)
    

    Most modern environments support the full set of IANA time zone identifiers (see the compatibility table here). However, keep in mind that the only identifier required to be supported by Intl is 'UTC', thus you should check carefully if you need to support older browsers or atypical environments (for example, lightweight IoT devices).

Libraries

There are several libraries that can be used to work with time zones. Though they still cannot make the Date object behave any differently, they typically implement the standard IANA timezone database and provide functions for using it in JavaScript. Modern libraries use the time zone data supplied by the Intl API, but older libraries typically have overhead, especially if you are running in a web browser, as the database can get a bit large. Some of these libraries also allow you to selectively reduce the data set, either by which time zones are supported and/or by the range of dates you can work with.

Here are the libraries to consider:

Intl-based Libraries

New development should choose from one of these implementations, which rely on the Intl API for their time zone data:

  • Luxon (successor of Moment.js)
  • date-fns-tz (extension for date-fns)
  • Day.js (when using its Timezone plugin)

Non-Intl Libraries

These libraries are maintained, but carry the burden of packaging their own time zone data, which can be quite large.

  • js-joda/timezone (extension for js-joda)
  • moment-timezone* (extension for Moment.js)
  • date-fns-timezone (extension for older 1.x of date-fns)
  • BigEasy/TimeZone
  • tz.js

* While Moment and Moment-Timezone were previously recommended, the Moment team now prefers users chose Luxon for new development.

Discontinued Libraries

These libraries have been officially discontinued and should no longer be used.

  • WallTime-js
  • TimeZoneJS

Future Proposals

The TC39 Temporal Proposal aims to provide a new set of standard objects for working with dates and times in the JavaScript language itself. This will include support for a time zone aware object.

Common Errors

There are several approaches that are often tried, which are in error and should usually be avoided.

Re-Parsing

new Date(new Date().toLocaleString('en', {timeZone: 'America/New_York'}))

The above approach correctly uses the Intl API to create a string in a specific time zone, but then it incorrectly passes that string back into the Date constructor. In this case, parsing will be implementation-specific, and may fail entirely. If successful, it is likely that the resulting Date object now represents the wrong instant in time, as the computer's local time zone would be applied during parsing.

Epoch Shifting

var d = new Date();
d.setTime(d.getTime() + someOffset * 60000);

The above approach attempts to manipulate the Date object's time zone by shifting the Unix timestamp by some other time zone offset. However, since the Date object only tracks time in UTC, it actually just makes the Date object represent a different point in time.

The same approach is sometimes used directly on the constructor, and is also invalid.

Epoch Shifting is sometimes used internally in date libraries as a shortcut to avoid writing calendar arithmetic. When doing so, any access to non-UTC properties must be avoided. For example, once shifted, a call to getUTCHours would be acceptable, but a call to getHours would be invalid because it uses the local time zone.

It is called "epoch shifting", because when used correctly, the Unix Epoch (1970-01-01T00:00:00.000Z) is now no longer correlated to a timestamp of 0 but has shifted to a different timestamp by the amount of the offset.

If you're not authoring a date library, you should not be epoch shifting.

For more details about epoch shifting, watch this video clip from Greg Miller at CppCon 2015. The video is about time_t in C++, but the explanation and problems are identical. (For JavaScript folks, every time you hear Greg mention time_t, just think "Date object".)

Trying to make a "UTC Date"

var d = new Date();
var utcDate = new Date(Date.UTC(d.getUTCFullYear(), d.getUTCMonth(), d.getUTCDate(), d.getUTCHours(), d.getUTCMinutes(), d.getUTCSeconds(), d.getUTCMilliseconds()));

In this example, both d and utcDate are identical. The work to construct utcDate was redundant, because d is already in terms of UTC. Examining the output of toISOString, getTime, or valueOf functions will show identical values for both variables.

A similar approach seen is:

var d = new Date();
var utcDate = new Date(d.getUTCFullYear(), d.getUTCMonth(), d.getUTCDate(), d.getUTCHours(), d.getUTCMinutes(), d.getUTCSeconds(), d.getUTCMilliseconds());

This is approach passes UTC values into the Date constructor where local time values are expected. The resulting Date object now represents a completely different point in time. It is essentially the same result as epoch shifting described earlier, and thus should be avoided.

The correct way to get a UTC-based Date object is simply new Date(). If you need a string representation that is in UTC, then use new Date().toISOString().

2 of 16
250

As Matt Johnson said

If you can limit your usage to modern web browsers, you can now do the following without any special libraries:

new Date().toLocaleString("en-US", {timeZone: "America/New_York"})

This isn't a comprehensive solution, but it works for many scenarios that require only output conversion (from UTC or local time to a specific time zone, but not the other direction).

So although the browser can not read IANA timezones when creating a date, or has any methods to change the timezones on an existing Date object, there seems to be a hack around it.

Consider the following function

function changeTimezone(date, ianatz) {

  // suppose the date is 12:00 UTC
  var invdate = new Date(date.toLocaleString('en-US', {
    timeZone: ianatz
  }));

  // then invdate will be 07:00 in Toronto
  // and the diff is 5 hours
  var diff = date.getTime() - invdate.getTime();

  // so 12:00 in Toronto is 17:00 UTC
  return new Date(date.getTime() - diff); // needs to substract

}

However, closely looking at the return value, this can be simplified to:

function changeTimezone(date, ianatz) {
  return new Date(date.toLocaleString('en-US', {
    timeZone: ianatz
  }));
}

// E.g.
var here = new Date();
var there = changeTimezone(here, "America/Toronto");

console.log(`Here: ${here.toString()}\nToronto: ${there.toString()}`);

🌐
Reddit
reddit.com › r/learnjavascript › question regarding dates and time zones
r/learnjavascript on Reddit: Question regarding dates and time zones
August 10, 2023 -

We are trying to add times to our dates in an older app and the dates were almost always stored as partially formed ISO strings. Not a hard rule since times were never used before.

Now I need to start displaying the times with the dates and allowing the user to alter the times on the front end.

Example: we get a date ISO string from the backend as 2008-08-15T00:00:00.

When I create a Date object from it, I get the date in my local time zone (GMT-0600). In this example, Fri, August 15, 2008 00:00:00 (GMT-0600).

Then later when the edit form is submitted with no change to the day or time, I convert the Date object to an ISO string and strip the milliseconds and time zone code to keep it consistent with the current format in the database. In this example it returns 2008-08-15T06:00:00 to the backend.

Notice the time was provided as 00:00:00 but after parsing it and then converting to an ISO string, I've now added 6 hours to the time and am returning 06:00:00.

I am thinking I could convert it to GMT-0000 before converting to an ISO string but I'm not sure if that is the cleanest solution. Has anyone else had a similar scenario and what would you suggest to do to make this work (that doesn't include altering all the dates in the DB, we're planning for that down the road)?

Top answer
1 of 5
2
Had the same issue, our DB and servers are set to UTC but in browser they're set to user timezone, which JS always assumes. To ensure JS knows what timezone the time you're providing is in, append it to the end of your timestamp. For example: new Date(myTimestamp + " UTC"). Yep, looks horrific but is a valid and recommended solution apparently. Welcome to JavaScript! Also be sure to check Safari support as the wah Safari handles dates is very messed up.
2 of 5
2
new Date() defaults to using the local timezone pulled from the browser which is pulled from the OS. When dealing with times the best way to handle is to store dates in ISO or UTC, or if you want to store local times, store the IANA timezone string. ('America/Chicago' or 'America/Sao_Paulo') and always track the users locale string ('en-US', 'pt-BR) Then explicitly use both locale and IANA. So when you display on the frontend you can use something like this: new Date().toLocaleString( 'en-US', { dateStyle: 'medium', timeStyle: 'medium', timeZone: 'America/Chicago' } ) new Date() in the browser assumes UTC but toString converts to local. Give it a date without time new Date('2022-02-22') and it will convert FROM UTC TO your local standard time. The ASSUMPTION is this string comes from standard server time. date-fns and Luxon do the opposite. They assume '2022-02-22' is local time. parseISO('2022-02-22') without specifying timezone converts FROM local TO local. That's why they feel more intuitive if you're not paying attention. I HIGHLY encourage always using toLocaleString for formatting, even if you're using Luxon or date-fns. Don't give your users these manually formatted "MM/yyyy" things. Locale string formats are locale aware (sometimes dates go before moths), lowercase months when they're supposed to be lowercase, and handle translations. (Yeah! Translations!) So months days, weekdays, etc. will be translated. And for Spanish speaking countries they will use more standard things like 'de' which translates to 'of'. Aug 11, 2023, 2:32:00 PM 11 de ago. de 2023, 14:32:00
Find elsewhere
🌐
CoreUI
coreui.io › blog › how-to-manage-date-and-time-in-specific-timezones-using-javascript
How to Manage Date and Time in Specific Timezones Using JavaScript · CoreUI
January 22, 2025 - These libraries handle complex cases like daylight saving transitions and support a wide range of timezone data. For date input and selection in forms, explore the CoreUI React Date Picker or Bootstrap Date Picker for intuitive and customizable solutions. When building global applications, you often need to schedule events for users in different regions. JavaScript’s Intl.DateTimeFormat API can dynamically adjust for the user’s local timezone.
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › how-to-convert-date-to-another-timezone-in-javascript
How to Convert Date to Another Timezone in JavaScript? - GeeksforGeeks
July 12, 2025 - let date = new Date(Date.UTC(2012, ... console.log('USA date: ', usaTime); ... The toLocaleString() method is used to return a string that formats the date according to the locale and options specified....
🌐
Netlify
netlify.com › blog › how-to-get-timezone-in-javascript-with-edge-functions
How to get the user‘s timezone in JavaScript with Edge Functions
You don‘t need client-side JavaScript to adapt and localize dates and times according to timezone — use timezone data in Netlify Edge Functions with JavaScript native Date()!
🌐
W3Schools
w3schools.com › jsref › jsref_gettimezoneoffset.asp
JavaScript Date getTimezoneOffset() Method
<a> <abbr> <address> <area> <article> <aside> <audio> <b> <base> <bdo> <blockquote> <body> <br> <button> <canvas> <caption> <cite> <code> <col> <colgroup> <datalist> <dd> <del> <details> <dfn> <dialog> <div> <dl> <dt> <em> <embed> <fieldset> <figcaption> <figure> <footer> <form> <head> <header> <h1> - <h6> <hr> <html> <i> <iframe> <img> <ins> <input> button <input> checkbox <input> color <input> date <input> datetime <input> datetime-local <input> email <input> file <input> hidden <input> image <input> month <input> number <input> password <input> radio <input> range <input> reset <input> sear
🌐
Day.js
day.js.org › docs › en › timezone › timezone
Time Zone · Day.js
The list of all time zone names can be found in the IANA database. For legacy or unsupported environments, please use a proper polyfill. ... dayjs.extend(utc) dayjs.extend(timezone) // current time zone is 'Europe/Berlin' (offset +01:00) // Parsing dayjs.tz("2013-11-18 11:55:20", "America/Toronto") // '2013-11-18T11:55:20-05:00' // Converting (from time zone 'Europe/Berlin'!) dayjs("2013-11-18 11:55:20").tz("America/Toronto") // '2013-11-18T05:55:20-05:00'
🌐
Quora
quora.com › How-do-you-convert-date-time-to-local-user-specific-time-zone-JavaScript-ReactJS-Date-moment-js-and-development
How to convert date time to local user specific time zone (JavaScript, ReactJS, Date, moment.js, and development) - Quora
Answer: Given a JavaScript Date object, say in a variable called [code ]myDateVar[/code], you just need to call [code ]myDateVar.toLocaleTimeString()[/code], and you’ll get the time outputted in the user’s internet browser’s time zone.
🌐
Medium
toastui.medium.com › handling-time-zone-in-javascript-547e67aa842d
Handling Time Zone in JavaScript. Recently, I worked on a task of adding… | by TOAST UI | Medium
August 30, 2019 - Therefore, if you create a Date object directly using user input data, the data will directly reflect the client’s local time zone. As I mentioned earlier, JavaScript does not provide any arbitrary way to change time zone.
🌐
Reddit
reddit.com › r/learnjavascript › how to create a date object using local date/timezone?
r/learnjavascript on Reddit: How to create a date object using local date/timezone?
April 17, 2022 -

I'm using a date picker component from bootstrap in a Vue app. It gives you the picked date as a string in YYYY-MM-DD format. I want to use this date string to make a date object.

The problem is if I just do new Date(dateString) then it treats it as a GMT date, so if the date string is 2022-05-19, it will create a date object whose ISO string is '2022-05-19T00:00:00Z'. If I then use this date later to convert to my local time (using date.toLocaleString()) it will be 5-18-22 at 7 PM (which makes since because my time zone is GMT-5)

The problem is that the user will be treating the selected date in the date picker as local time, but the date object created from it treats it as GMT. How do I fix this discrepancy?

🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Date › toLocaleString
Date.prototype.toLocaleString() - JavaScript | MDN
The toLocaleString() method of Date instances returns a string with a language-sensitive representation of this date in the local timezone. In implementations with Intl.DateTimeFormat API support, this method delegates to Intl.DateTimeFormat.
🌐
SheCodes
shecodes.io › athena › 8564-setting-date-time-in-a-specific-timezone-in-javascript
[JavaScript] - Setting Date & Time in a Specific Timezone in JavaScript
Learn how to set the date & time in a specific timezone in Javascript by defining the required timezone and adjusting the timezone offset. List of valid IANA Time Zone database included.