Convert uncommon date format to timestamp in most efficient manner possible?

后端 未结 4 434
鱼传尺愫
鱼传尺愫 2020-12-09 04:06

I have a date in this format: 20101101120000

I need to convert it to a timestamp with PHP.

I\'ve been searching the PHP docs online, but can\'t find anything

4条回答
  •  借酒劲吻你
    2020-12-09 04:35

    You can do this with DateTime::createFromFormat:

    $d = DateTime::createFromFormat('YmdGis', '20101101120000');
    

    $d is now a DateTime instance. You can either convert it to a timestamp with $d->getTimestamp() or use the DateTime methods on it.

    Note that this requires PHP 5.3.

提交回复
热议问题