如何为时间戳设置Laravel Carbon时区? [英] How to set Laravel Carbon timezone for timestamps?

查看:1822
本文介绍了如何为时间戳设置Laravel Carbon时区?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个主要位于CET地区的项目.我在config/app.php中设置了CET, 但是基地中所有的枢轴时间戳都以UTC时间存储了吗?

I have a project which is primarily based in CET region. I set CET in config/app.php, but all pivot timestamps in the base are stored in UTC time?

如何为时间戳设置全局"时区?

How can I set "global" timezone for timestamps?

我做了这个测试:

<?php
$timezone = date_default_timezone_get();
echo "The current server timezone is: " . $timezone;
echo "<br />".date('m/d/Y h:i:s a', time());

$mytime = Carbon\Carbon::now();
echo "<br />".$mytime->toDateTimeString();
?>

结果如下:

The current server timezone is: CET
06/09/2016 12:06:04 pm
2016-06-09 11:06:04

tnx 是

推荐答案

Carbon使用默认的 DateTime PHP对象,因此请使用 date_default_timezone_set()函数,例如: date_default_timezone_set('Europe/London');

Carbon uses the default DateTime PHP object, so use the date_default_timezone_set() function, for example: date_default_timezone_set('Europe/London');

这篇关于如何为时间戳设置Laravel Carbon时区?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆