tags:

views:

33

answers:

1

ok well i have this error with a counter i made witch is suppost to count down to 0

$time=1283593330+(60*15);
$time3= time();
$time2=$time-$time3;

1283593330=Sat, 04 Sep 2010 09:42:10 GMT

Error is this: when the $time3 timestamp hit the timestamp for $time it says 05:00:00 instande of 00:00:00. This is the code i use to call it.

Time left: '.date('g:i:s   ',$time2).'<br />

im not sure if im doing something wrong, if 5 is the main time for unix_timestamp or the date commend in PHP

is there anyway to fix this? or is this from of timestamp just that bad of a idea for what i need.

+2  A: 

Your time zone is 5 hours ahead of UTC: you say 1283593330 is 09:42, but it's actually 04:42 UTC.

When $time2 is zero, this represents the Unix time epoch: this is midnight UTC on 1st January 1970. So when you output this using date, it shows that time in your time zone: 00:00 UTC which is 05:00 in your time zone.

What's important is that $time2 is zero when the target time is reached.

Given that your counter is counting down 15 minutes, you can get the remaining time like this:

$hours = floor($time2 / 60);
$mins = $time2 % 60;
printf("Time left: %d:%02d\n", $hours, $mins);
Richard Fearn
just changed my server time and got it working ty so much
Catles
Do you mean you've changed the time zone on your server? That isn't necessary. Displaying `$time2` as a date/time using `date` doesn't really make sense; it's a time difference, not an absolute time. It's easy to get this working without requiring specific timezone settings on the server.
Richard Fearn