Jump to content

php time for australia please ???


linux1880

Recommended Posts

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");
?>

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());
?>

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

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');

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.