I really hope that some of you can help me understand the following problem, and hopefully offer a solution to the problem...
Background: I'm writing a script, that uses both local server time and also uses US/Pazific time. The script uses $_sessions and a automatic page refresh every 3 minuttes. I want users of the script to be able to define $offset in the config file, that holds the time difference in hours from their local time to US/Pazific time. $ldate + $ltime represents local server time, and $udate + $utime represents US/Pazific time.
When the server the script runs on passes midnight, php completelly ignores $offset and $udate_tmp. Which results in $udate,$utime is equal to $ldate and $ltime. In my case, my server is 9 hours ahead of US/Pazific time. However, I want to be able to offer the script to other users, and they must also be able to define $offset, and thereby showing both their local time and US/Pazific time.
based on your problem, i can find wrong logic here. if you decremented the time with the offset, why did you only change the hour? when the result is negative, it means your in another day and not in the same day. i think you can see this from your code.
some workaround:
1. you can set an absolute reference to GMT (gmdate and gmmktime)
2. you should do proper maths to calculate relative time difference from your server time.
regards,
__________________
just an ignorant noob with moronic solution...
you solve the problem yourself. anyway, for me, it's working but it's not working properly. let's assume date('H') is equal to i which 0<i<9, i E A. if we supply date('H') with, let's say 5, now the hour would be: 5-9 = -4. this is quite impossible for your script to return the proper time. instead, you should do proper math to solve this issue.
__________________
just an ignorant noob with moronic solution...
I've come up with a script that displays this right... I'm waiting for my USB flash drive to come back from replacement... I have to get it off the computer here that doesn't have internet... I'll post it here when I get it. So far it works with any given time and time offset.
It works for any timezone that I've tried it on, including positive GMT offsets. This code prints the formatted date in central time no matter where the server is. The timezone can be changed by simply changing "$gmt" to your offset. If it needs clarification, or modification to suit your purposes, let me know.
PHP Code:
<?php
//get GMT offset at the server
$offset = date('O');
//algebraically add the GMT offset for central time (600)
$gmt = "-600";
$time_off = $offset - $gmt;
//divide it by 100 to get hours
$off = $time_off/100;
//if time is in DST, add an hour to the offset
$offset = $off - date('I');
//make the timestamp
$maketime = mktime(date('G') - $offset, date('i'), date('s'), date('n'), date('j'), date('Y'), date('I'));
//print the formatted date using the timestamp
print date('l, F jS, Y - g:i a', $maketime);
?>