【问题标题】:php 12 hr format to 24hr format time convertingphp 12小时格式到24小时格式时间转换
【发布时间】:2009-12-31 07:10:03
【问题描述】:

我有一个像“6:15pm”这样的字符串。 PHP中是否有任何函数可以将其直接转换为24小时格式。即到“18:15”?

【问题讨论】:

    标签: php time


    【解决方案1】:

    我建议将strtotime()date() 一起使用:

    print date("H:i", strtotime("6:15pm"));
    

    【讨论】:

      【解决方案2】:

      您可以使用strtotime()

      echo date('H:i', strtotime('6.:15pm'));
      

      【讨论】:

        【解决方案3】:
        //Call this once before the 1st date/time operation
        date_default_timezone_set('Europe/Zurich');
        
        echo date('H:i', strtotime('6:15pm'));
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2019-12-24
          • 1970-01-01
          • 2013-07-14
          • 1970-01-01
          • 2011-11-17
          • 1970-01-01
          相关资源
          最近更新 更多