【问题标题】:Converting timestamp into readable format将时间戳转换为可读格式
【发布时间】:2014-09-21 15:15:02
【问题描述】:

我知道这已经被问过一百万次了,但其他答案都没有真正给我我需要的东西。我的时间戳如下:

2014-05-10T21:30:00+0200

我如何将其转换为:

演出将于 2014 年 5 月 10 日晚上 21:30 开始

我正在使用 PHP。任何帮助将不胜感激!

【问题讨论】:

标签: php timestamp unix-timestamp


【解决方案1】:

您应该首先将您的time 转换为timestamp

$timestamp = strtotime("2014-05-10T21:30:00+0200");

然后根据需要显示它。

echo date("h.m.Y", $timestamp);

或者你可以使用DateTime

$objDateTime= new DateTime("2014-05-10T21:30:00+0200");
$objDateTime->format(DateTime::ISO8601); // Another way to get an ISO8601 formatted string

【讨论】:

    【解决方案2】:

    这是一个 Atom 日期,而不是时间戳。你可能想做这样的事情:

    function print_event_time($atom, $name='Gig', $verb='starting'){
      list($s1, $s2) = explode(',',date('g:ia,d/m/y', strtotime("$atom")));  
      echo sprintf('%s is %s at %s on %s',$name,$verb,$s1,$s2);
    }
    
    echo print_event_time('2014-05-10T21:30:00+0200');
     //> Gig is starting at 7:30pm on 10/05/14
    
    echo print_event_time('2014-05-10T21:30:00+0200', 'Shindy', 'rollin');
     //> Shindy is rollin at 7:30pm on 10/05/14
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-11-06
      • 1970-01-01
      • 2016-02-13
      • 2011-09-18
      • 1970-01-01
      相关资源
      最近更新 更多