简体   繁体   中英

My PHP datetime code doesn't work properly

The code shown below isn't working properly, can you tell me why that is? My web browser shows a 504 error when loading the script.

It just cannot access any datetime object. Even though I copy the code from php manual.

<?php
        
$start = new DateTime('2012-07-01');
?>

Whats most probably wrong with your piece of code, is that you do not actually include the time after a 'T' keyword for php to understand what to print out.

For Example:

<?php
$start = new DateTime('2012-07-01T00:00:00');
>?

But still if thats not the case. Try this instead: https://www.php.net/manual/en/function.date.php

创建一个 DateTimeImmutable 对象就可以了

$date = new DateTimeImmutable('2000-01-01');

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