I'd like to take a time given by the user (supposedly the current time) and find out the time zone of it. I am thinking I'll use the correct CST and somehow compare them. Any ideas?
Thanks.
Printable View
I'd like to take a time given by the user (supposedly the current time) and find out the time zone of it. I am thinking I'll use the correct CST and somehow compare them. Any ideas?
Thanks.
you would have to get the time zone of the user and subtract it from the servers timezone. all of this can be done with the date() function.
somehting like this
$timeoffset = intval(date("H",12*60*60)-gmdate("H",12*60*60));
date(h:i A, time()+(-8-$timeoffset)*3600);
-8 = the users timezone
Thank you but I have the opposite problem. I will be given a time and date of the user and I want to figure out what their time zone is.
well, you could try this
date("M-d g:ia T");
the T will print out the timezone but I believe it is for the servers timezone. also how do you plan on getting the users current time without knowing there timezone? if you use date to get the users time I don't think that will work, it is getting teh servers time.
The date is provided by their system from AIM. That isn't important here though. I am getting the time from the user, and I'd like to determine what time zone that they are in based on the time provided. This should be possible. I just need to compare the time given with the correct time. Analyze the hour offset.
well you could try localtime.
ifyou already have the time from the user then you need to subtract it like you said, but how would you know to subtract it or add it?
I am not sure. Maybe I could do this with substr and strpos. Just getting the hour that the user has given me, and comparing it. Hmm
strpos and substr aren't going to tell you anything. you will need to know if they are forward or backward from your server.
just getting the time I don't believe you could do this. are they a dat ahead or a day behind. you don't have enough info just from the time.
I have their date too.
ok that will solve one problem, but now you ned to figure out which way to go, forward or backward. where is the server located?
Central Time Zone.
Here is some sample information that I get from the user:
12/16/02 9:47:25 AM
ok now check this out.
you have this info
12/16/02 9:47:25 AM
and you know the server is -5 I believe correct?
now if it was me that sent that time it would be easy, I am at -8 and that is my time you show, so the servers time is 12:47 I think
so you know that I am 3 hours slower than the server so you can just add -3 to the servers timezone.
so you would need to get the date and then if it is a day ahead you know you have to go back so you would add a postivie number, if the date is the same then you have to add a negative number. also you would need to see which way the time is, above or below the servers time.
I think that should work if I have my math right.
What? lol. Sorry went over my head. Can you maybe write some sample code to help illustrate please?
you're kidding right :)
if you didn't understand that than how are you going to write the code :p
ok give me a bit and I will see what I can come up with.
Well I understand some of what you said, I understand the concept, but I don't see how I'm supposed to gather and compare the data. Thank you. :)
ok, this is very rough and not tested. I don't know how you got the date and time from the user but you can edit it from here. try it and let me kow if it works. I just pulled this out of my *** :p
I will also play around with it when I have time.PHP Code:<?
echo "localtime: ". localtime();
$usrtime = "12/16/02 9:47:25 AM";
$newusertime = strtotime($usrtime);
$serverTime = time();
$serverTimezone = intval(date("H",12*60*60)-gmdate("H",12*60*60));
$newzone = floor ($serverTime - $usrtime) / 3600); // 3600 = 1 hour
if ($usrtime > $serverTime){
$status = "-";
} else {
$status = "+";
}
$Userzone = $serverTimezone $status $newzone2;
?>
I appreciate it. I'll try it when I get a chance.
BTW: I'm kinda new to php but not new to programming. What does php do when you put variables just straight next to each other with a space like you did on the last line?
PHP Code:$Userzone = $serverTimezone $status $newzone2;
it should just print out ok, if not add a . in between them. generally I don't have a problem but sometimes php gets picky. :)
I didn't know you could ommit the .
thanks.
this is more of what you want. it is close but still has problems, goes past +12 and -12 so you can edit it like you want to get the correct Time zone
PHP Code:<?
$usrtime = "12/17/02 11:05:25 AM";
$newusertime = strtotime($usrtime);
$serverTime = time();
$serverTimezone = intval(date("H",12*60*60)-gmdate("H",12*60*60));
$newzone = floor(($serverTime - $newusertime) / 3600);
if ($newusertime > $serverTime){
$status = "+";
} else {
$status = "-";
}
$zone = $status . $newzone;
$Userzone = floor($serverTimezone + $zone);
echo "Users Timezone is: ".$Userzone
// 3600 = 1 hour
?>
Thank you! Thanks a lot phpman.
The site I am using this for is http://www.leetomatic.net