开发者

Get South Africa Standard Time In Php

this function is used to get current time of my s开发者_Go百科ystem, 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜