[英]Time stored in the DB is 2 hours before the picked one
我正在研究Symfony 2.7中的一個項目。
我們得到以下問題:
在某些地方,用戶必須選擇事件或提醒等的日期和時間。他們可以使用基礎datetimepicker選擇它。
請求發送的數據似乎很好:[title => Vermifuge,date => 05.10.2016 16:00,pet => 22,description =>,renewable => 1,delay => 3 months,nextDate => 05.01。 2017 16:00,active => 1,_token => QTvz3ykjcngQh2Y5SvW5KWdO2D35Ue8m8CfFtZBQxDc](來自symfony工具欄的c / c)
但是在控制器中我轉儲值:
$this->setup($request);
$entity = $this->findOrThrowNotFound($id);
$this->denyAccessUnlessGranted('edit', $entity->getPet(), 'Unauthorized access!');
$editForm = $this->createCreateForm($entity);
$editForm->handleRequest($request);
dump($editForm['date']);
dump($editForm['date']->getData());
第一次轉儲是:
Form {#2369 ▼
-config: FormBuilder {#2370 ▶}
-parent: Form {#2363 ▶}
-children: OrderedHashMap {#2371 ▶}
-errors: []
-submitted: true
-clickedButton: null
-modelData: DateTime {#2336 ▶}
-normData: DateTime {#2336 ▶}
-viewData: "05.10.2016 16:00"
-extraData: []
-transformationFailure: null
-defaultDataSet: true
-lockSetData: false
}
第二個:
DateTime {#4733 ▼
+"date": "2016-10-05 14:00:00.000000"
+"timezone_type": 1
+"timezone": "+00:00"
}
所以在某個時刻,時間會發生變化。
在我的phpinfo()我有:
啟用日期/時間支持
“Olson”時區數據庫版本2016.3
時區數據庫內部
默認時區Europe / Zurich
謝謝你的幫助
看起來您的數據庫的時間與服務器不同,請在您的數據庫中嘗試此查詢:
SELECT now();
然后嘗試從php轉儲它:
$now = new DateTime();
echo $now->format('Y-m-d H:i:s'); // MySQL datetime format
echo $now->getTimestamp();
希望它能幫到你......
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.