PHP date format converting

后端 未结 4 1561
青春惊慌失措
青春惊慌失措 2020-11-29 13:00

Here is what I have:

$dateFormat = \'M d, Y\';
$dateString = \'January 23, 2010\';

What I need is a timestamp of $dateString s

4条回答
  •  爱一瞬间的悲伤
    2020-11-29 13:30

    Given my understanding of the question and what is available in PHP, you need to relax your expectations somewhere or other.

    A 'simple' solution (which has already been discounted) would be to force using PHP 5.3 and the tools available in it.

    A less simple solution would be to take those additions and port them over to PHP-land (with PHP 4 compatibility, good luck).

    Another route of exploration would be to consider the occasions where strtotime does not work for you and working around those limitations.

    How widely variant are your format strings? It may be possible to come up with a solution mapping format strings to functions/methods (to do that date parsing) providing they're pretty restricted.

提交回复
热议问题