Converting separate month, day and year values into a timestamp

前端 未结 7 784
不知归路
不知归路 2021-02-12 16:32

I have a month value (1-12), day value (1-31), and a year value (2010,2011,2012). I also have a hour value and a minute value.

How can I give this to strtotime()

7条回答
  •  醉话见心
    2021-02-12 17:25

    You can provide it to function strtotime() in many ways, as mentioned in documentation. Some examples include:

    $your_time = strtotime('12/31/2011 9:59');
    $your_time = strtotime('2011-12-31 9:59');
    $your_time = strtotime('December 31, 2011 9:59');
    

    etc. It really is very flexible.

    You can find the list of valid formats in the documentation, and that is (from the "Compound Formats" list in the mentioned documentation) for example:

    • 10/Oct/2000:13:55:36 -0700,
    • 2008:08:07 18:11:31,
    • 2008-08-07 18:11:31,
    • 2008-07-01T22:35:17.02,
    • 2008-07-01T22:35:17.03+08:00,
    • 20080701T22:38:07,
    • 20080701T9:38:07,
    • 20080701t223807,
    • 20080701T093807,
    • 2008-7-1T9:3:37,

    (this is really copy of the documentation)

提交回复
热议问题