Friday, January 20, 2012

PHP and GMT

I have to deal with financial data a bunch and one of the issues that I often run into is dealing with time issues especially when dealing with FIX messages.  A nice function I have found that helps to deal with handling time conversion in PHP is gmstrftime.  This function converts time to Greenwich Mean Time from your current time zone.  So, you do not have to worry about doing the conversion yourself for the time.  Here is an example.

date_default_timezone_set('America/New_York');
$cur_time = mktime(22, 0, 0, 12, 31, 2011);
echo strftime("%b %d %Y %H:%M:%S", $cur_time) . "\n";
echo gmstrftime("%b %d %Y %H:%M:%S", $cur_time) . "\n";

This code will output the following:

Dec 31 2011 22:00:00
Jan 01 2012 03:00:00

So, for easy GMT conversion, PHP has you covered.



No comments:

Post a Comment