linux1880 Posted March 29, 2010 Share Posted March 29, 2010 how can i echo australia sydney time in php pls help. Quote Link to comment https://forums.phpfreaks.com/topic/196923-php-time-for-australia-please/ Share on other sites More sharing options...
o3d Posted March 30, 2010 Share Posted March 30, 2010 date_default_timezone_set('Australia/Sydney'); http://nz2.php.net/manual/en/function.date-default-timezone-set.php Quote Link to comment https://forums.phpfreaks.com/topic/196923-php-time-for-australia-please/#findComment-1033865 Share on other sites More sharing options...
linux1880 Posted March 30, 2010 Author Share Posted March 30, 2010 actually i just created script but everything below this script disappear in the live site. Please help <?php $dateTime = new DateTime("now", new DateTimeZone('Europe/Warsaw')); //echo "Warsaw" . $dateTime->format("G:i"); $dateTimeZone = new DateTimeZone('GMT'); $dateTime->setTimezone($dateTimeZone); echo "<br />"; echo "UK " . $dateTime->format("G:i"); echo " | "; $dateTimeZoneAu = new DateTimeZone('Australia/Sydney'); $dateTime->setTimezone($dateTimeZoneAu); echo "AUS(SYD) " . $dateTime->format("G:i"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/196923-php-time-for-australia-please/#findComment-1033871 Share on other sites More sharing options...
linux1880 Posted March 30, 2010 Author Share Posted March 30, 2010 actually the above code in working on my wamp server but not in the production server Quote Link to comment https://forums.phpfreaks.com/topic/196923-php-time-for-australia-please/#findComment-1033882 Share on other sites More sharing options...
joel24 Posted March 30, 2010 Share Posted March 30, 2010 I was havin troubles on my server a while ago too, assuming because of the server's security limitations. either way I now use this little script i made up Note- the script sets both the MYSQL and the PHP to use the australia/sydney timezone. <?php //timezone php putenv('TZ=Australia/Sydney'); //get offset, including daylight savings because mysql won't! $currentOffset = "+".(date("Z") / 60 / 60).":00"; //timezone mysql $update_tz = @mysql_query("SET time_zone = '$currentOffset'") or die(mysql_error()); ?> Quote Link to comment https://forums.phpfreaks.com/topic/196923-php-time-for-australia-please/#findComment-1033896 Share on other sites More sharing options...
linux1880 Posted March 30, 2010 Author Share Posted March 30, 2010 Is there a way without using mysql database ? I will simply need to echo it on the page, I don't need to insert it in database. any help pls. Quote Link to comment https://forums.phpfreaks.com/topic/196923-php-time-for-australia-please/#findComment-1034010 Share on other sites More sharing options...
RichardRotterdam Posted March 30, 2010 Share Posted March 30, 2010 Could be a number of things why your script didn't work. Are you running the same versions of PHP on your dev as production? And can you turn on errors? maybe this works: <?php date_default_timezone_set('Australia/Sydney'); echo date('H:i'); // 24 hour format echo "<br />"; echo date('h:i a'); // 12 hour format Quote Link to comment https://forums.phpfreaks.com/topic/196923-php-time-for-australia-please/#findComment-1034020 Share on other sites More sharing options...
joel24 Posted April 1, 2010 Share Posted April 1, 2010 Is there a way without using mysql database ? I will simply need to echo it on the page, I don't need to insert it in database. any help pls. yes, you can just use either of these two //timezone php putenv('TZ=Australia/Sydney'); //timezone php date_default_timezone_set('Australia/Sydney'); Quote Link to comment https://forums.phpfreaks.com/topic/196923-php-time-for-australia-please/#findComment-1035009 Share on other sites More sharing options...
darkagn Posted April 1, 2010 Share Posted April 1, 2010 Also you can adjust your php.ini file to set your default timezone for your server. Search your config file for the date.timezone setting and change it like so: date.timezone = Australia/Sydney Reboot your web server, then forever after all date function calls will be in the Sydney timezone without the need to call the date_default_timezone_set function beforehand. Quote Link to comment https://forums.phpfreaks.com/topic/196923-php-time-for-australia-please/#findComment-1035014 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.