How to format an UTC date to use the Z (Zulu) zone designator in php?

前端 未结 5 1368
闹比i
闹比i 2020-12-02 17:11

I need to display and handle UTC dates in the following format:

2013-06-28T22:15:00Z

As this format is part of the ISO8601 stand

5条回答
  •  天命终不由人
    2020-12-02 17:12

    To do this with the object-oriented style date object you need to first set the timezone to UTC, and then output the date:

    function dateTo8601Zulu(\DateTimeInterface $date):string {
      return $date
        ->setTimezone(new \DateTimeZone('UTC'))
        ->format('Y-m-d\TH:i:s\Z');
    }
    

提交回复
热议问题