How to convert the time from AM/PM to 24 hour format in PHP?

前端 未结 7 2266
旧时难觅i
旧时难觅i 2020-12-07 22:58

For example, I have a time in this format:

eg. 

09:15 AM
04:25 PM
11:25 AM

How do I convert it to :

09:15
16:25
23:25
         


        
7条回答
  •  失恋的感觉
    2020-12-07 23:23

    If you use a Datetime format see http://php.net/manual/en/datetime.format.php

    You can do this :

    $date = new \DateTime();
    echo date_format($date, 'Y-m-d H:i:s');
    #output: 2012-03-24 17:45:12
    
    echo date_format($date, 'G:ia');
    #output: 05:45pm
    

提交回复
热议问题