简体   繁体   中英

DATETIME / timezone?

I am using this to store DATETIME in mysql

validation.php

//more code
$date = new DateTime("2012-01-01 23:59:59", new DateTimeZone('Europe/Paris'));
$dt = $date->format('Y-m-d H:i:s');

//and I am posting into my DATETIME field:

Insert...Value($dt)

1.. I get no errors but the date/time posted is 0000-00-00 00-00-00

What am I doing wrong?

2.. Is there a way to store date formatted as DD-MM-YYYY?

您可以在存储到数据库之前使用PHP设置时区

$date = new DateTime("2012-07-05 16:43:21", new DateTimeZone('Europe/Paris')); 

You have to post

$var_date = $date->format('Y-m-d H:i:sP') 

not directly $date

Did it... Correct syntax is:

$date = new DateTime(null, new DateTimeZone('Europe/Paris')); 
$dt = $date->format('Y-m-d H:i:sP');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM