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";
}