[PHP] Re: Time zone in date function
On 31/01/2012 01:55, Ron Piggott wrote: On my clients account when I use “echo date(‘D, d M Y H:i:s');” the output is 5 hours ahead of us. How do I change it to my local time? Is there a way to specify “Eastern” time zone? I expect this would work: echo date(‘D, d M Y H:i:s' , ( strtotime( date(‘D, d M Y H:i:s') – 21600 ) ) ); I would prefer to specify Eastern time, so if the web host changes a server setting it will remain in Eastern time zone. Ron Hi Ron, I use this function to get the current time in a particular timezone: ?php /** * Return the current local time by timezone name * @param string $timezone * @return array * @author Ian Gibbons */ function getNowByTimezone($timezone){ $remote_timezone= new DateTimeZone($timezone); $remote_time= new DateTime(now, $remote_timezone); return getDate(strtotime($remote_time-format(Y-m-d H:i:s))); } ? Example: ? $london_time = getNowByTimezone(Europe/London); echo date(D, d M Y H:i:s, $london_time[0]); ? Regards Ian -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Time zone in date function
On Tue, 31 Jan 2012 14:57:41 +1300, Simon J Welsh wrote: On 31/01/2012, at 2:55 PM, Ron Piggott wrote: On my clients account when I use ?echo date(?D, d M Y H:i:s');? the output is 5 hours ahead of us. How do I change it to my local time? Is there a way to specify ?Eastern? time zone? I expect this would work: echo date(?D, d M Y H:i:s' , ( strtotime( date(?D, d M Y H:i:s') ? 21600 ) ) ); I would prefer to specify Eastern time, so if the web host changes a server setting it will remain in Eastern time zone. Ron You can set the timezone for your script using date_default_timezone_set() http://php.net/manual/en/function.date-default-timezone-set.php (wrap your lines, folks!) Is there a reason _not_ to use viz: putenv(TZ=America/Anguilla); ?? Or, is it simple Just The Linux Way(tm) , i.e. there's always more than one way to do a 'thing'? Jonesy -- Marvin L Jones| jonz | W3DHJ | linux 38.24N 104.55W | @ config.com | Jonesy | OS/2 * Killfiling google banter.com: jonz.net/ng.htm -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Time zone in date function
On Tue, Jan 31, 2012 at 4:22 PM, Jonesy gm...@jonz.net wrote: On Tue, 31 Jan 2012 14:57:41 +1300, Simon J Welsh wrote: On 31/01/2012, at 2:55 PM, Ron Piggott wrote: On my clients account when I use ?echo date(?D, d M Y H:i:s');? the output is 5 hours ahead of us. How do I change it to my local time? Is there a way to specify ?Eastern? time zone? I expect this would work: echo date(?D, d M Y H:i:s' , ( strtotime( date(?D, d M Y H:i:s') ? 21600 ) ) ); I would prefer to specify Eastern time, so if the web host changes a server setting it will remain in Eastern time zone. Ron You can set the timezone for your script using date_default_timezone_set() http://php.net/manual/en/function.date-default-timezone-set.php (wrap your lines, folks!) Is there a reason _not_ to use viz: putenv(TZ=America/Anguilla); ?? Or, is it simple Just The Linux Way(tm) , i.e. there's always more than one way to do a 'thing'? Jonesy From the PHP Manual: every call to a date/time function will generate a E_NOTICE if the timezone isn't valid, and/or a E_WARNING message if using the system settings or the TZ environment variable. So that will generate E_WARNING messages. - Matijn -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Time zone in date function
On Tue, 31 Jan 2012 17:15:48 +0100, Matijn Woudt wrote: On Tue, Jan 31, 2012 at 4:22 PM, Jonesy gm...@jonz.net wrote: Is there a reason _not_ to use viz: putenv(TZ=America/Anguilla); ?? Or, is it simple Just The Linux Way(tm) , i.e. there's always more than one way to do a 'thing'? From the PHP Manual: every call to a date/time function will generate a E_NOTICE if the timezone isn't valid, and/or a E_WARNING message if using the system settings or the TZ environment variable. So that will generate E_WARNING messages. Ya, but... I am using that _very_ statement and get no E_WARNING. The timezone illustrated _is_ valid. IWFM. I believe the PHP manual is 'awkwardly' written in this case. Better would be if that *whole* sentence above was re-written beginning with If the timezone is invalid, every call , and/or an E_WARNING ... As written, it could be construed to mean an E_WARNING is _always_ generated for setting the TZ environment variable. Jonesy -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php