[英]PHP date time to Unix time Stamp
How can I convert string "MdY::H:i:s" to unix timestamp in php. 如何将字符串“ MdY :: H:i:s”转换为php中的unix时间戳。 I just realized manipulating date and time must be the most time consuming entity in any programming language. 我只是意识到操纵日期和时间必须是任何编程语言中最耗时的实体。
Trivial Question: Why do you think there isn't any universal date time format. 琐碎的问题:为什么您认为没有通用的日期时间格式。 Why are there so many variations of same data? 为什么相同数据有这么多变化? AArrhh. AArrhh。
The OOP way (requires PHP >= 5.3.0): OOP方式(需要PHP> = 5.3.0):
$dt = DateTime::createFromFormat("M-d-Y::H:i:s", $input);
$ts = $dt->getTimestamp();
You should of course check the return value of createFromFormat
(it's false
if an error occurs) but you should also definitely check DateTime::getLastErrors()
; 当然,您应该检查createFromFormat
的返回值(如果发生false
则为false
),但也应该绝对检查DateTime::getLastErrors()
; otherwise you might be surprised if eg your input has a day of "Jan 32". 否则,如果您输入的日期为“ 1月32日”,您可能会感到惊讶。 See my answer here for more info. 有关更多信息,请参见此处 。
我有此问题服务不可用(带有消息)ResponseText:错误:在boolean上调用成员函数getTimestamp()如何解决此问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.