this function is used to get current time of my system, I want to get South Africa time, so plz guide me.
$today = time () ;
For example:
<?php
date_default_timezone_set('Africa/Johannesburg');
echo date('Y-m-d H:i:s', time());
$d = new DateTime("now", new DateTimeZone("Africa/Johannesburg"));
echo $d->format("r");
gives
Mon, 07 Jun 2010 02:02:12 +0200
You can change the format. See http://www.php.net/manual/en/function.date.php
time()
gives the number of seconds since January 1 1970 00:00:00 GMT (excluding leap seconds), so it doesn't depend on the timezone.
EDIT: For a countdown, you can do:
$tz = new DateTimeZone("Africa/Johannesburg");
$now = new DateTime("now", $tz);
$start = new DateTime("2010-06-11 16:00:00", $tz);
$diff = $start->diff($now);
echo "Days: " . $diff->format("%d") . "\n";
echo "Hours: " . $diff->format("%h") . "\n";
echo "Minutes: " . $diff->format("%i") . "\n";
echo "Seconds: " . $diff->format("%s") . "\n";
The time()
function returns the same value all around the world. Its return value is not dependent on the local time zone.
To convert a time value to your local time, call the localtime()
function.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With