DateTime->format(epoch) returning the wrong date

前端 未结 4 2006
春和景丽
春和景丽 2021-01-22 04:55

I am working on a project and I am having an issue formatting an epoch time to a human readable time.

I have the following epoch time 1428512160 and when I

4条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-22 05:32

    You need to add an @ for the timestamp in the DateTime class, like this:

    $dt = new DateTime("@" . $supportDetails["Reported"]);
                      //^ See here
    

    You can also see this in the manual. And a quote from there:

    Unix Timestamp "@" "-"? [0-9]+ "@1215282385"

    Also note that the current timezone is getting ignored, which you can also see in the manual:

    Note: The $timezone parameter and the current timezone are ignored when the $time parameter either is a UNIX timestamp (e.g. @946684800) or specifies a timezone (e.g. 2010-01-28T15:00:00+02:00).

提交回复
热议问题