PHP basics – Date and time handling with time zones

So here it is, how to what I did with java, but with php. Fun stuff!

date_default_timezone_set($timeZone);
$epoch = mktime($hour, $min, $sec, $month, $day, $year);
date_default_timezone_set($serverTimeZone);

echo date("Y-m-d H:i:s",$epoch);

mktime generates the epoch time for the date entered, you change the time zone back to the server and there you go, converted date time :)

Tags: , , , , , ,

Author:Alan Hamlyn

-- Alan Hamlyn Founder of Wuup
  • http://topsy.com/trackback?utm_source=pingback&utm_campaign=L2&url=http://www.wuup.co.uk/php-basics-date-and-time-handling-with-time-zones Tweets that mention PHP basics – Date and time handling with time zones | Wuup — Topsy.com

    [...] This post was mentioned on Twitter by Alan Hamlyn, Alan Hamlyn, Tammy Kahn Fennell, Tammy Kahn Fennell, MarketMeTweet and others. MarketMeTweet said: RT @Wuup PHP basics Date and time handling with time zones http://bit.ly/clQ6ZK [...]