Does PHP have an inverse of the date() function (other than strtotime())?

前端 未结 7 536
别跟我提以往
别跟我提以往 2021-01-17 14:53

Is there a function that uses the date() format to interpret a string?

echo date(\'s-i-H d:m:Y\', 1304591364); // 34-29-17 05:05:2011

// Does t         


        
相关标签:
7条回答
  • 2021-01-17 15:14

    The function mktime seems to do what you want.

    Check the help over at php.net:

    http://php.net/manual/en/function.mktime.php

    EDIT : indeed strtotime may be more convenient for you, I did not know that function, glad to learn.

    0 讨论(0)
  • 2021-01-17 15:21

    Try this to reverse:

    $x = '2013-09-15';

    $x = implode('-', array_reverse(explode('-', $x)));

    // now $x = '15-09-2013'

    0 讨论(0)
  • 2021-01-17 15:24

    You would typically use strtotime for that:

    echo strtotime('2011-05-05 17:29:34');
    

    From the manual:

    strtotime — Parse about any English textual datetime description into a Unix timestamp

    See valid date and time formats to be sure that the string you are passing in will be parsed correctly.

    0 讨论(0)
  • 2021-01-17 15:30

    Yes you can use:

    echo strtotime("2011-05-05 17:29:34");
    
    0 讨论(0)
  • 2021-01-17 15:35

    PHP 5.4+ will print 1359674625

    echo date_create_from_format('j/n/Y G:i:s','1/2/2013 1:23:45')->getTimestamp();
    
    0 讨论(0)
  • 2021-01-17 15:36

    The real answer to this question the way I mean it is http://www.php.net/manual/en/datetime.createfromformat.php

        $date = date_create_from_format('j-M-Y', '15-Feb-2009');
        echo date_format($date, 'Y-m-d'); // 2009-02-15
    
    0 讨论(0)
提交回复
热议问题