【问题标题】:php date change to 12 hour format and add gmt +3 [closed]php日期更改为12小时格式并添加gmt +3 [关闭]
【发布时间】:2013-08-19 19:52:22
【问题描述】:

我将日期用作:

 $date = date('m-d-Y H:i:s');

这会将其插入为 24 小时,而我想要的是 12 小时格式并添加 GMT +3,我该怎么做?

【问题讨论】:

  • H:i:s 部分更改为 h:i:s 以获取 12 小时格式。
  • 感谢添加 gmt + 3
  • 您阅读手册了吗? php.net/manual/en/function.date.php
  • 你需要在这个问题上更清楚......你想要文字字符“GMT +3”吗?是否要将日期/时间转换为 GMT +3 的时区?或者您想指定这个给定的日期/时间是 GMT +3 吗?
  • 我想将日期/时间转换为 GMT + 3

标签: php date


【解决方案1】:

你可以使用

  $date = date("m-d-Y h:i:s", strtotime("now +3 GMT"));

【讨论】:

    【解决方案2】:

    如果你想要 GMT +3 时区,你可以应用这个:

    date_default_timezone_set('Etc/GMT+3');
    

    虽然我不推荐它,因为 PHP will not longer support that timezone。您可以使用one of the supported ones。对于 12 小时格式的日期,请以这种方式使用:

    $date = date('m-d-Y h:i:s');
    

    小写的h format character 代表

    带前导零的小时的 12 小时格式

    【讨论】:

    • 感谢您的帮助。我只是看不懂手册。
    【解决方案3】:

    date_default_timezone_set("GMT"); 用于更改时区..(将 gmt 替换为 +3 时区名称)

    $date = date('m-d-Y h:i:s'); 12 小时格式..

    并阅读手册http://php.net/manual/en/function.date.php

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-08-31
      • 2015-08-29
      • 2014-08-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多