Re: Unix date

From: Date: Fri, 28 Dec 2007 16:00:25 +0000
Subject: Re: Unix date
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-266322@lists.php.net to get a copy of this message
On Dec 28, 2007 10:46 AM, tedd <tedd@sperling.com> wrote: > Hi gang: > > Using: > > $unix_in = 1255845600; > > echo(date("M d, Y h:i:s a",$unix_in)); > > On one sever, produces: Oct 18, 2009 02:00:00 am > > But on another sever, produces: Oct 18, 2009 12:00:00 am > > This difference appears to be a combination of "time-zone" and > "daylight-savings" considerations. In other words, the function > date() looks at the server's time (whatever that is set for, right or > wrong) and uses that for the calculation. > > So, what's the best method in keeping things consistent across > servers? Is there one? <? if(function_exists(date_default_timezone_set)) { date_default_timezone_set('UTC'); } $unix_in = 1255845600; echo date("M d, Y h:i:s a",$unix_in)."\n"; ?> It requires PHP 5 >= 5.1.0, hence the function_exists() condition. -- Daniel P. Brown [Phone Numbers Go Here!] [They're Hidden From View!] If at first you don't succeed, stick to what you know best so that you can make enough money to pay someone else to do it for you.

« previous php.general (#266322) next »