php strtotime() DateTime 类模拟方法

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13722878/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 05:57:35  来源:igfitidea点击:

strtotime() DateTime class analog method

php

提问by s.webbandit

Is there a method of DateTimeclass which acts like strtotime()core PHP function?

是否有一个DateTime类的方法像strtotime()核心 PHP 函数一样?

For example strtotime('last monday');

例如 strtotime('last monday');

回答by deceze

That would be DateTime::__construct:

那将是DateTime::__construct

$date = new DateTime('Sunday');

回答by shadyyx

As strtotime()returns long UNIX timestamp, the DateTime has the method getTimestamp().

由于strtotime()返回长 UNIX 时间戳,因此 DateTime 具有方法getTimestamp()

$date = new DateTime('2012-01-25 19:44:49.123');
echo $date->getTimestamp();

回答by JNDPNT

I think you are looking for DateTime.createFromFormat()

我想你正在寻找 DateTime.createFromFormat()

http://php.net/manual/en/datetime.createfromformat.php

http://php.net/manual/en/datetime.createfromformat.php