Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Laravel时区不工作_Php_Laravel_Laravel 4_Timezone_Laravel 3 - Fatal编程技术网

Php Laravel时区不工作

Php Laravel时区不工作,php,laravel,laravel-4,timezone,laravel-3,Php,Laravel,Laravel 4,Timezone,Laravel 3,我正在尝试将UTC时区转换为Singapore Time echo $Date->format('Y-m-d H:i:s'); echo '<br>'; echo with(new Carbon\Carbon($Date->format('Y-m-d H:i:s')))->tz('Asia/Singapore')->format('Y-m-d H:i:s'); exit; echo$Date->format('Y-m-dh:

我正在尝试将
UTC
时区转换为
Singapore Time

    echo $Date->format('Y-m-d H:i:s');
    echo '<br>'; 
    echo with(new Carbon\Carbon($Date->format('Y-m-d H:i:s')))->tz('Asia/Singapore')->format('Y-m-d H:i:s');
    exit;
echo$Date->format('Y-m-dh:i:s');
回声“
”; 与(新碳纤维\碳纤维($Date->format('Y-m-dh:i:s'))->tz('Asia/Singapore')->format('Y-m-dh:i:s'); 出口

它在
Localhost
中工作正常,但在
aws服务器中它同时显示
utc时间
。服务器和Localhost都设置为
utc
时间。。我们如何解决这个问题呢?

我假设在您的例子中,
$Date
DateTime
对象(或
Carbon
对象)。您可以使用PHP
setTimeZone()
DateTimeZone

$Date = new DateTime($user->updated_at); // sample DateTime creation - also $Date = $user->updated_at; would work here

echo $Date->format("Y-m-d H:i:s")."<br />";

$Date->setTimezone(new DateTimeZone('Asia/Singapore'));
echo  $Date->format("Y-m-d H:i:s")."<br />";
试试这个,会有用的

 $timestamp ='1411205843'  //Timestamp which you need to convert 

 $sourceTimezone = new DateTimeZone('UTC');

 $destinationTimezone = new DateTimeZone('Asia/Singapore'); 

 $dt = new DateTime(date('m/d/Y h:i A', $timestamp), $sourceTimezone);
 $dt->setTimeZone($destinationTimezone);

 echo strtotime($dt->format('m/d/Y h:i A'));

我假设您拥有的
$Date
变量是一个(默认情况下在
Laravel
中可用)对象:

现在要设置
时区
,您可以使用以下任一选项:

$Date->timezone = new DateTimeZone('Asia/Singapore');
$Date->timezone = 'Asia/Singapore';
$Date->tz = 'Asia/Singapore';
您也可以从
app/config/app.php
中进行设置,如:

/*
|--------------------------------------------------------------------------
| Application Timezone
|--------------------------------------------------------------------------
|
| Here you may specify the default timezone for your application, which
| will be used by the PHP date and date-time functions. We have gone
| ahead and set this to a sensible default for you out of the box.
|
*/

'timezone' => 'Asia/Singapore',

你到底为什么要把
DateTime
类与
date()
strotime()
函数混在一起?只需使用
DateTime
类即可简单地解决此问题。。。我不想粗鲁,但你为什么要标记所有的拉威尔版本?首先,你的问题与拉威尔无关。可能是因为laravel4中的composer默认使用碳元素,但laravel3与您的问题无关
$Date->timezone = new DateTimeZone('Asia/Singapore');
$Date->timezone = 'Asia/Singapore';
$Date->tz = 'Asia/Singapore';
/*
|--------------------------------------------------------------------------
| Application Timezone
|--------------------------------------------------------------------------
|
| Here you may specify the default timezone for your application, which
| will be used by the PHP date and date-time functions. We have gone
| ahead and set this to a sensible default for you out of the box.
|
*/

'timezone' => 'Asia/Singapore',