Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.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-strotime()返回值_Php_Date_Time_Strtotime - Fatal编程技术网

PHP-strotime()返回值

PHP-strotime()返回值,php,date,time,strtotime,Php,Date,Time,Strtotime,以下代码段: echo date("d.m.Y-H:i:s", strtotime("01.01.2000-11:12:32")); 返回给我: 1970年1月1日-1:00:00 将“01.01.2000-11:12:32”转换为时间/日期对象以与当前时间戳进行比较的正确方法是什么 e、 g 这是由于本地化。尝试给出不同的格式,因为格式非常重要: echo date("d.m.Y-H:i:s", strtotime("01/01/2000 11:12:32")); echo date("d.

以下代码段:

echo date("d.m.Y-H:i:s", strtotime("01.01.2000-11:12:32"));
返回给我:

1970年1月1日-1:00:00

将“01.01.2000-11:12:32”转换为时间/日期对象以与当前时间戳进行比较的正确方法是什么

e、 g


这是由于本地化。尝试给出不同的格式,因为格式非常重要:

echo date("d.m.Y-H:i:s", strtotime("01/01/2000 11:12:32"));
echo date("d.m.Y-H:i:s", strtotime("01-01-2000 11:12:32"));
  • 日期和月份分隔符不应使用
  • 不能使用
    -
    分隔日期和时间
  • 如果您从其他来源获取输入,请尝试使用
    str\u replace

    echo date("d.m.Y-H:i:s", strtotime(str_replace(array(".", "-"), array("/", " "), "01.01.2000-11:12:32")));
    

    输出:

    尝试用
    -
    替换

    echo日期(“d.m.Y-H:i:s”,strotime(str_替换('.','-',01.01.2000 11:12:32))

    同时删除日期和时间之间的
    -

    您可以使用


    尝试将点改为斜线。@PraveenKumar so。。点是允许的吗?嗯,它们是。。但这是由于本地化。不是在左边,而是在右边。@PraveenKumar你是说。。日期(“d.m.Y-H:i:s”,标准时间(“01/01/2000-11:12:32”)?看到了。。将在几分钟内被接受。工作得很好。
    echo date("d.m.Y-H:i:s", strtotime(str_replace(array(".", "-"), array("/", " "), "01.01.2000-11:12:32")));
    
    $date = DateTime::createFromFormat('d.m.Y-H:i:s', '01.01.2000-11:12:32');
    $now = new DateTime();
    
    if ($now > $date) {
        echo "future";
    } else {
        echo "past";
    }