Reputation: 467
I want to create a php script to conduct an online contest all over the world at single time .
My first question.. can i really do it at one time span , if yes then HOW?
for eg. let's say i host a contest for 10 jun 2012 ,from 2-4 pm IST or wherever the server is . Now i want that users from all over the world should attend contest at this time only . how should i tell user about the converted local time zone of his? I dont want user should take pain for conversion of times and neither i'm willing to give a conversion tool for user's all over the world .
I want that user should enter the contest at his local timezone date and time being mentioned !.
Thanks in Advance !
Upvotes: 2
Views: 1253
Reputation: 17724
Its simple. Send the server time to the client (some hidden span or input.)
function getLocalTime(gmt) {
var min = gmt.getTime() / 1000 / 60; // convert gmt date to minutes
var localNow = new Date().getTimezoneOffset(); // get the timezone
// offset in minutes
var localTime = min - localNow; // get the local time
return new Date(localTime * 1000 * 60); // convert it into a date
}
//var strDate = [get text date sent from server here];
var dt = new Date(Date.parse(strDate));
var localDate = getLocalTime(dt);
//[Set value of your localTime here]
Convert this time to users local time using javascript. Display only the users local time to the user.
Contest will be held at : <span id='localTime'></span>
Upvotes: 0
Reputation: 422
Get the client's Timezone by setting a cookie or using an ajax call.
Upvotes: 1