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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.