I am using a JavaScript Date
class & trying to get the current date using getDate()
method. But obviously it is loading system date & time. I am running the code from India but I want to get the date & time of UK using the same method. How can I do that ?

- 13,617
- 16
- 88
- 129

- 3,753
- 11
- 53
- 95
-
4This thread is a poor cousin to the much more complete thread: http://stackoverflow.com/questions/10087819/convert-date-to-another-timezone-in-javascript which has a much better answer. Executive summary... use https://github.com/mde/timezone-js – Brett Hannah Jul 01 '13 at 10:14
-
3@BrettHannah Executive summary would be to use [moment.js](http://stackoverflow.com/questions/10087819/convert-date-to-another-timezone-in-javascript/18612568#18612568) as timezone-js does [not](http://stackoverflow.com/questions/10087819/convert-date-to-another-timezone-in-javascript#comment27512245_10089167) support DST ;-) – nachtigall Oct 06 '15 at 09:33
9 Answers
If you know the UTC offset then you can pass it and get the time using the following function:
function calcTime(city, offset) {
// create Date object for current location
var d = new Date();
// convert to msec
// subtract local time zone offset
// get UTC time in msec
var utc = d.getTime() + (d.getTimezoneOffset() * 60000);
// create new Date object for different city
// using supplied offset
var nd = new Date(utc + (3600000*offset));
// return time as a string
return "The local time for city"+ city +" is "+ nd.toLocaleString();
}
alert(calcTime('Bombay', '+5.5'));
Taken from: Convert Local Time to Another

- 443
- 4
- 19

- 99,167
- 15
- 158
- 162
-
16Your `utc` thing is wrong. `d.getTime` *is* already in UTC milliseconds. Yet, instead of `toLocaleString()` you will need to use `.toUTCString()`! – Bergi Feb 19 '13 at 20:12
-
58Remember that the offset for a location can change (daylight savings/british summer time). – James M May 14 '13 at 17:22
-
3You actually need to be subtracting getTimezoneOffset output rather than adding it - that offset is for going from local time to UTC, not the other way around. – kotekzot Dec 26 '13 at 05:06
-
Is it possible to change the format? For example I only need the time in hours, minutes, seconds and AM/PM – MRC Oct 30 '14 at 14:53
-
@Bergi is correct your comment. I did what you mentioned and I get the correct date. – carzogliore Nov 07 '14 at 04:16
-
23This is not a good answer. If you hardcode in an offset you'll be off about half the year if it has daylight savings time. – horsejockey Nov 20 '17 at 17:15
-
-
@kotekzot, you dont need that do that because the getTimezoneOffset method set the sign appropriately. – user618677 Sep 13 '19 at 12:20
-
@MRC, there are a lot of method attached that Date object, so you can. – user618677 Sep 13 '19 at 12:20
-
@horsejockey Unless you're using Arizona time, which never changes based on daylight savings time :-) – user2966445 Nov 22 '21 at 03:10
You could use Intl.DateTimeFormat
.
let options = {
timeZone: 'Europe/London',
year: 'numeric',
month: 'numeric',
day: 'numeric',
hour: 'numeric',
minute: 'numeric',
second: 'numeric',
},
formatter = new Intl.DateTimeFormat([], options);
console.log(formatter.format(new Date()));
Alternatively, if you're formatting just once instead of bulk use Date.prototype.toLocaleDateString()
.
(new Date()).toLocaleString([], options)
Unfortunately browsers are not required to understand timezones other than UTC, so try
these blocks and figure out an alternative in case it fails, for example fetch the timezone offset from a server.

- 2,041
- 25
- 19

- 4,828
- 2
- 25
- 33
-
-
correct answer, it is called the International API, and is built-in, in most newer browsers, you should check if it exists first.. naturally... - reference: [Intl](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl) – Jan 08 '16 at 15:50
-
-
8This works very very well. Here's the listing of browser support: https://caniuse.com/#search=Intl – Joshua Pinter Feb 16 '19 at 04:38
-
1
-
List of time zones: https://stackoverflow.com/a/54500197. You may be interested in `America/Los_Angeles` and `America/New_York` – Luke Miles Jun 20 '22 at 23:43
One way to do this is to use getLocaleString, like this:
Create a date object:
date = new Date(0)
If you are in Berlin, this should convert to this string:
Thu Jan 01 1970 01:00:00 GMT+0100 (CET)
Get the hours in Athens:
date.toLocaleString('de-DE', {hour: '2-digit', hour12: false, timeZone: 'Europe/Athens' })
'02'
Get the hours in Shanghai:
date.toLocaleString('de-DE', {hour: '2-digit', hour12: false, timeZone: 'Asia/Shanghai' })
'08'

- 1,475
- 1
- 20
- 35
-
2Side note: `Date.prototype.toLocaleString` only works on IE11+, Firefox 29+, Safari 11+, etc. See [this](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleDateString) – Raptor Dec 22 '16 at 10:10
-
1not only this. the IANA timezone names are only available chrome and firefox.. – iRaS Jan 02 '19 at 11:10
-
First, you should use 'en-US' because it is the only locale supported in Node < 13 (ie. 100% of production Node use at this time), but also you need to account for minutes because some timezone have a half hour offset. – Tom Nov 07 '19 at 18:33
You can use getUTCDate()
and the related getUTC...()
methods to access a time based off UTC time, and then convert.
If you wish, you can use valueOf()
, which returns the number of seconds, in UTC, since the Unix epoch, and work with that, but it's likely going to be much more involved.

- 10,479
- 4
- 40
- 63
This is Correct way to get ##
function getTime(offset)
{
var d = new Date();
localTime = d.getTime();
localOffset = d.getTimezoneOffset() * 60000;
// obtain UTC time in msec
utc = localTime + localOffset;
// create new Date object for different city
// using supplied offset
var nd = new Date(utc + (3600000*offset));
//nd = 3600000 + nd;
utc = new Date(utc);
// return time as a string
$("#local").html(nd.toLocaleString());
$("#utc").html(utc.toLocaleString());
}

- 153
- 1
- 11
-
Anyone if wondering how to call this function then here is an example if you want to get time for India getTime(5.5); – Irfan Raza Nov 12 '18 at 09:38
-
5All the suggested method in this thread doesn't consider day light saving (where it applies) so better use moment timezone library to make life easy. – Irfan Raza Nov 12 '18 at 09:39
-
2Downvoting, because the answer expects the OP to know the offset. Presumably the OP is working from a time zone string although he is not explicit about this. The OP needs to use the Intl API, or a library like Luxon or Moment. – Adam Leggett Nov 12 '18 at 23:41
-
@AdamLeggett A simple Google search of nearly any location's time has UTC+/-# in the proprietary result, so it is a bit unfair to assume the OP is incapable of such a simple task. – Abandoned Cart Dec 30 '19 at 06:54
-
@AbandonedCart the answer isn't general enough for most programmatic purposes unless it includes the answer of how to retrieve the offset. This is by no means simple - the offset can vary throughout the year and has changed at least several times in most locales through history. A database of all this is large. – Adam Leggett Jan 02 '20 at 17:49
-
@AdamLeggett Please share your answer, but try to keep it somewhat efficient. – Abandoned Cart Jan 02 '20 at 23:52
-
-
If it's really important that you have the correct date and time; it's best to have a service on your server (which you of course have running in UTC) that returns the time. You can then create a new Date on the client and compare the values and if necessary adjust all dates with the offset from the server time.
Why do this? I've had bug reports that was hard to reproduce because I could not find the error messages in the server log, until I noticed that the bug report was mailed two days after I'd received it. You can probably trust the browser to correctly handle time-zone conversion when being sent a UTC timestamp, but you obviously cannot trust the users to have their system clock correctly set. (If the users have their timezone incorrectly set too, there is not really any solution; other than printing the current server time in "local" time)

- 5,077
- 2
- 28
- 41
before you get too excited this was written in 2011
if I were to do this these days I would use Intl.DateTimeFormat. Here is a link to give you an idea of what type of support this had in 2011
original answer now (very) outdated
Date.getTimezoneOffset()
The getTimezoneOffset() method returns the time difference between Greenwich Mean Time (GMT) and local time, in minutes.
For example, If your time zone is GMT+2, -120 will be returned.
Note: This method is always used in conjunction with a Date object.
var d = new Date()
var gmtHours = -d.getTimezoneOffset()/60;
document.write("The local time zone is: GMT " + gmtHours);
//output:The local time zone is: GMT 11

- 17,572
- 7
- 45
- 53
The .getTimezoneOffset()
method should work. This will get the time between your time zone and GMT. You can then calculate to whatever you want.

- 597
- 2
- 10
- 22
short answer from client-side: NO, you have to get it from the server side.

- 8,694
- 30
- 36
-
19You're wrong. It's actually more difficult on the server, because the client knows both what timezone it's in, and what time it is there. The server only has half of that equation. – CommunistPancake Nov 21 '11 at 05:33
-
1This seems to be the only answer for the OP's actual question. The OP wants the UK time regardless of where the client is situated. You can get the UTC time which is the timezone of the UK, but there's no way to easily determine if it's DST. – Tim Tisdall Feb 12 '13 at 15:09
-
5UTC is not the UK's timezone. This is a common misunderstanding. UTC does not have a timezone and is standard. UK is same as UTC in winter and is UTC+1 in summer. UK's timezone is either British Standard Time or British Summer Time (both abbreviated with BST... just to add to the confusion!) – the_new_mr Oct 03 '14 at 14:17
-