【问题标题】:I need to isolate the time from a date / timestamp我需要将时间与日期/时间戳隔离开来
【发布时间】:2016-11-30 06:27:37
【问题描述】:

我有一个日期字符串或日期戳,以最简单的为准。

字符串如下所示:

Thursday, 01 December 2016 19:00 - 22:00

或者,如果没有结束时间:

Saturday, 01 December 2016 19:00

我也可以将它们作为日期戳。

$event 对象包含如下信息:

[dtstart] => 1479232800 

[dtstart] => 1481094000 
[dtend] => 1481151599 
//apparently if there is no end time, the endtime is set to 23:59:59.

我试过这样做:

echo 'start '.date('H:i','$event->dtstart')

但这并没有给我任何东西。

【问题讨论】:

  • PHP 字符串基础知识:date('H:i',$event->dtstart), ' 假定字符串为文字。

标签: php date timestamp


【解决方案1】:

改变这一行:

echo 'start '.date('H:i','$event->dtstart');

echo 'start '.date('H:i',$event->dtstart);    // remove the quotes from 2 parameter and try again, it will give you the result like:

10:00 开始

【讨论】:

    【解决方案2】:

    从 $event->dtstart 中删除引号

     echo 'start '.date('H:i',$event->dtstart);   
    
    example:  echo date('H:i',1171502725);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-06-13
      • 2018-05-22
      • 1970-01-01
      • 2012-11-23
      • 2017-08-08
      • 1970-01-01
      • 2016-09-15
      相关资源
      最近更新 更多