这个函数用来获取我系统的当前时间,我想得到南非的时间,所以请指导我.
$today = time () ;
Run Code Online (Sandbox Code Playgroud)
Lau*_*nen 15
例如:
<?php
date_default_timezone_set('Africa/Johannesburg');
echo date('Y-m-d H:i:s', time());
Run Code Online (Sandbox Code Playgroud)
$d = new DateTime("now", new DateTimeZone("Africa/Johannesburg"));
echo $d->format("r");
Run Code Online (Sandbox Code Playgroud)
给
Mon, 07 Jun 2010 02:02:12 +0200
您可以更改格式.见http://www.php.net/manual/en/function.date.php
time() 给出自1970年1月1日00:00:00 GMT(不包括闰秒)以来的秒数,因此它不依赖于时区.
编辑:倒计时,您可以:
$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";
Run Code Online (Sandbox Code Playgroud)