I am launching my new website, which is to be launched at 9 am italian time. Now i gave
dateFuture = new Date(2013,0,30,9,00,00);
but it takes my local pc date in india. How can i show the website at the italian 9 am?
Asked
Active
Viewed 337 times
0

istepaniuk
- 4,016
- 2
- 32
- 60

SREE ANI
- 304
- 2
- 5
- 13
-
It's very much worth pointing out that even with this, a javascript check is still just local check.. All someone would need to do is just change their system clock manually and this check will no longer prevent early access to the system. – Seph Jan 31 '13 at 05:09
-
@Seph: You are assuming what the OP needs this for. He might also just want a countdown displayed. – Sani Huttunen Jan 31 '13 at 10:01
-
@SaniHuttunen from the OP "How can i show the website at the italian 9 am?" indicates that they want to use this javascript check to prevent users from seeing the new webpage until 9am rather than just a simple countdown. – Seph Jan 31 '13 at 10:27
2 Answers
0
To get the local time in India when the time is 9 AM in Italy:
var offset = new Date().getTimezoneOffset() / 60 ;
var d = new Date(Date.UTC(2013,0,30,9 + offset,0,0));

Sani Huttunen
- 23,620
- 6
- 72
- 79
-
-
@istepaniuk: If it is to be launched at 9 am Italian time it is to be launched at 9 am. Daylight savings or not. – Sani Huttunen Jan 30 '13 at 07:11
-
-
@istepaniuk: The point in using UTC is that the launch is scheduled at 9 am GMT+1. OP needs to convert the specified time to local time in india. – Sani Huttunen Jan 30 '13 at 09:08
-
indeed, op wants launch at 9am GMT+1 (8am UTC), that's why the time in India is irrelevant. – istepaniuk Jan 30 '13 at 09:18
-
0
I understand you want to prevent a page from being seen before a certain time in a specific place. As you know, JavaScript runs in the browser, and with the time alone you can't tell if the user is opening the page in Italy or elsewhere.
The closest you can go is to make sure that it will be after 9am in that time zone.
var now = new Date();
var nowUtc = new Date(
now.getUTCFullYear(),
now.getUTCMonth(),
now.getUTCDate(),
now.getUTCHours(),
now.getUTCMinutes(),
now.getUTCSeconds());
var eightAmUTC = new Date(2013,0,30,8,00,00); // 8am UTC is 9am In Italy for this date.
var nowIsAfter9InItaly = nowUtc > eightAmUTC;
nowIsAfter9InItaly will be true
if it after 9am in italy, on Jan 30th, false
otherwise.

istepaniuk
- 4,016
- 2
- 32
- 60
-
@Seph Except that it works. But you can begin by posting a correct answer, pointing out the mistake, or even editing it yourself. The method used to get nowUtc is described here http://stackoverflow.com/questions/948532/how-do-you-convert-a-javascript-date-to-utc – istepaniuk Jan 30 '13 at 17:01