View Full Version : Time zones

Creative Insanity
01-11-2006, 09:11 PM
Ok doing a little more here and because my hoster is in the states and I am in NZ as you would be aware the time that is echoed is incorrect.

But one thing I could not suss out was time zones. Since I am NZST or GMT +12 how would I add that in the echo below so the time placed is correct for NZ from my hoster?

<?php echo date('l dS \of F Y h:i:s A'); ?>

01-12-2006, 09:00 AM
here is a function monkey i have used for such an issue

$current is the current machine.
$target is the timezone you want to calculate. In hours

For example, GMT -05:00 should
be -5. GMT +12:00 should be 12. You can use the returned timestamp with the date() function.

echo date('r', zonechange(-5, 10));
would echo the date for a +10:00 timezone on a machine in -05:00.

function LORzone($current, $target) {
$current = -1 * $current;
$zonedate = mktime(date('G'), date('i'), date('s'), date('n'),
date('j'), date('Y'), 1) + (($current + $target) * 3600);
return $zonedate;
LORzone(0, 0);

echo date('r', LORzone(-1, 12));

Creative Insanity
01-12-2006, 06:16 PM
Ahh ok, I understand that now. Hmmm
Ta dj.

01-16-2006, 07:37 AM

here is another i have used which is easier to get your head around

$yr = date("Y");
$mn = date("m");
$dy = date("d");
$offset = 1;
$lastmonth = $yr = date("Y");
$mn = date("m");
$dy = date("d");
$offset = 1;
$lastmonth = strftime("%Y/%m/%d", mktime(0,0,0,$mn,$dy-$offset,$yr));

$today = date("Y/m/d");

$today = date("Y/m/d");

it shouldnt be hard to convert into hours, mins, seconds

change your offset value to hours difference and where i have
$lastmonth = strftime("%Y/%m/%d", mktime(0,0,0,$mn,$dy-$offset,$yr));

you can see i am subtracting the offset from $dy ($dy-$offset) so just change that to do the calc on your hours

Creative Insanity
01-16-2006, 08:59 AM
Cheers dj I have it all sussed from your lat post thanks. ;)

It works a treat also.