iconicCreator Posted June 1, 2011 Share Posted June 1, 2011 I am in a Central Time Zone, I was searching for a count down script that shows the number of days left to an event. I stumbled upon this script which uses several function to display the messages. However, the time is about an hour behind or at least not Central Time Zone. The time is the same on my local and remote servers, so I conclude it has to do with the script. I am not sure how to resolved this. Here it is: <?php class event{ var $today; var $eventDate; function event($d,$m,$y){ $this->eventDate = mktime(0,0,0,$m,$d,$y); $this->today = date("d-m-y"); } function daysLeft(){ $daysUntilEvent = date('z',$this->eventDate); $currentDay=date('z'); $daysRemain = $daysUntilEvent - $currentDay; return $daysRemain; } function eventOver(){ if($this->daysLeft() <=0 ){ return 'Next Event is July 10th.'; }else{ return 'Event Begins in <span class="daysToEvent">'.$this->daysLeft().'</span> Days!'; } } } $event = new event(24,06,2011); echo $event->eventOver(); ?> Thanks everyone! IC Link to comment https://forums.phpfreaks.com/topic/238115-php-count-down-and-time-zones/ Share on other sites More sharing options...
fugix Posted June 1, 2011 Share Posted June 1, 2011 you can set the default timezone ofhere the script by using the function Link to comment https://forums.phpfreaks.com/topic/238115-php-count-down-and-time-zones/#findComment-1223563 Share on other sites More sharing options...
xyph Posted June 1, 2011 Share Posted June 1, 2011 Check this out! http://php.net/manual/en/function.date-default-timezone-set.php Link to comment https://forums.phpfreaks.com/topic/238115-php-count-down-and-time-zones/#findComment-1223565 Share on other sites More sharing options...
fugix Posted June 1, 2011 Share Posted June 1, 2011 Check this out! http://php.net/manual/en/function.date-default-timezone-set.php same link i posted...lol...just realized my sentence got all jumbled..weird Link to comment https://forums.phpfreaks.com/topic/238115-php-count-down-and-time-zones/#findComment-1223574 Share on other sites More sharing options...
iconicCreator Posted June 1, 2011 Author Share Posted June 1, 2011 Check this out! http://php.net/manual/en/function.date-default-timezone-set.php same link i posted...lol...just realized my sentence got all jumbled..weird Thank you, I think I had looked at that link before but I shall play around with it and see what happens. Thanks again. Link to comment https://forums.phpfreaks.com/topic/238115-php-count-down-and-time-zones/#findComment-1223579 Share on other sites More sharing options...
xyph Posted June 1, 2011 Share Posted June 1, 2011 Here's how I'd do it with >=PHP5.3 and OOP <?php class event { private $_eventDate, $_datetime, $_timezone = 'America/Vancouver'; public function __construct( $d,$m,$y ) { $date = $y.'-'.$m.'-'.$d.' 23:59:59'; $this->_datetime = new DateTime( $date, new DateTimeZone($this->_timezone) ); } private function daysLeft() { $now = new DateTime( NULL, new DateTimeZone($this->_timezone) ); return floor(($this->_datetime->getTimestamp() - $now->getTimestamp()) / 86400); } public function eventOver() { $daysLeft = $this->daysLeft(); if($daysLeft <= 0 ){ return 'Next Event is July 10th.'; }else{ return 'Event Begins in <span class="daysToEvent">'.$daysLeft.'</span> Days!'; } } } $obj = new event( 10,10,2011 ); echo $obj->eventOver(); ?> Link to comment https://forums.phpfreaks.com/topic/238115-php-count-down-and-time-zones/#findComment-1223616 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.