Getting past date/timezone warnings for PHP in OS X
If you're scripting on a Mac with PHP and need to use date functions, you can't rely on the user to have set them in /etc/php.ini, so here's a neat little workaround.
<?php
if ( ! ini_get('date.timezone') ) {
$tz = exec( 'tz=`ls -l /etc/localtime` && echo ${tz#*/zoneinfo/}' );
ini_set( 'date.timezone', $tz );
}
?>
This should work well enough for OS X, but I don't think it works for many others.
Written by Shawn Patrick Rice
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Php
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#