【问题标题】:Getting date time from a string [duplicate]从字符串中获取日期时间[重复]
【发布时间】:2012-02-27 19:41:52
【问题描述】:

可能重复:
Convert timestamp to readable date/time PHP

给定 1328520572 作为日期时间字符串, 如何从中获取特定格式的日期时间?

我想使用

str = '1328520572';
str_ret=datetime.Parse("M:D:Y H:M:S",str);

【问题讨论】:

  • 给我们一个线索:你认为它应该返回什么日期/时间?
  • 提问前请使用搜索功能。谢谢。

标签: php


【解决方案1】:
$str = '1328520572';
echo date("M:D:Y H:M:S", (int)$str);

但是你的日期格式不对,请检查正确的格式here。

【讨论】:

    【解决方案2】:

    格式正确的datetime?

    $unix = '1328520572';
    $datetime = date('Y-m-d H:i:s', $unix); 
    

    【讨论】:

      【解决方案3】:

      $str_ret = date("m:d:Y H:i:s", $str);

      【讨论】:

      • 和 str 将是一个时间戳,你也忘记了变量之前的 $ ;-)
      【解决方案4】:

      试试这个:

      $str = '1328520572';
      $str_ret = date('M:D:Y H:M:S', strtotime($str));
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2013-04-01
        • 2015-05-11
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-08-14
        • 1970-01-01
        相关资源
        最近更新 更多