[英]PHP date/time to timestamp (custom format)
Any one got a function to like strtotime()
but the takes the format as input? 任何人都有一个喜欢
strtotime()
的函数,但是将格式作为输入?
For example I need to convert yyyymmdd
to a timestamp, or perhaps yyyyddmm
. 例如,我需要将
yyyymmdd
转换为时间戳,或者yyyyddmm
。 So I would like to specify the format used. 所以我想指定使用的格式。 Also Im on Windows so
strptime()
isn't an option. 我也在Windows上,因此
strptime()
不是一个选项。
PHP 5's DateTime
class has the createFromFormat
method which does what you need. PHP 5的
DateTime
类具有createFromFormat
方法, createFromFormat
您的需要。
However, it requires PHP 5.3 so it's not always an option (yet). 但是,它需要PHP 5.3,因此它并不总是一个选项。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.