How to Format an Utc Date to Use the Z (Zulu) Zone Designator in PHP

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

No, there is no special constant for the desired format. I would use:

$date->format('Y-m-d\TH:i:s\Z');

But you will have to make sure that the times you are using are really UTC to avoid interpretation errors in your application.

How to format php date using this format

I think this is what you want :

$date->format('Y-m-d\TH:i:s\Z');

EDIT :

Time Zones

To specify a time zone, you can either enter a date in UTC time by adding a "Z" behind the date - like this:

2002-09-24Z

DateTime Data Type

The dateTime data type is used to specify a date and a time.

The dateTime is specified in the following form "YYYY-MM-DDThh:mm:ss" where:

YYYY indicates the year
MM indicates the month
DD indicates the day
T indicates the start of the required time section
hh indicates the hour
mm indicates the minute
ss indicates the second

Convert UTC date time to local date time

Append 'UTC' to the string before converting it to a date in javascript:

var date = new Date('6/29/2011 4:52:48 PM UTC');
date.toString() // "Wed Jun 29 2011 09:52:48 GMT-0700 (PDT)"

How to convert datetime to yyyy-MM-dd'T'HH:mm:ss.SSSZ in PHP

@DanielW comments, use

For future readers, here is the working format: Y-m-d\TH:i:s.vO
(without colon in timezone) and Y-m-d\TH:i:s.vP (with colon in
timezone)
.

use

date('Y-m-d H:i:s.uZ', strtotime($created_at_input)); // yyyy-MM-dd'T'HH:mm:ss.SSSZ
date('c', strtotime($date_of_birth_input)); // yyyy-MM-ddTHH:mm:ss+00:00

eg:

echo date('Y-m-d\TH:i:s.vO', strtotime('2011-02-01 00:00:00')); // 2011-02-01T00:00:00.000+0000
echo date('Y-m-d\TH:i:s.vP', strtotime('2011-02-01 00:00:00')); // 2011-02-01T00:00:00.000+00:00
echo date('Y-m-d H:i:s.uP', strtotime('2011-02-01 00:00:00')); // 2011-02-01 00:00:00.000000+05:30

echo date(DATE_ATOM, strtotime('2011-02-01 00:00:00')); // 2011-02-01T00:00:00+05:30

echo date('c', strtotime('2011-02-01 00:00:00')); // 2011-02-01T00:00:00+05:30

Try

use date('c', strtotime($date_of_birth_input));

eg:

echo date('c', strtotime('2011-02-01 00:00:00')); //ouput: 2011-02-01T00:00:00+00:00 

see http://www.php.net/manual/en/function.date.php

Php Convert date time like 2017-01-10T18:00:00.000Z to standard time

you can use date('Y-m-d h:i:s', strtotime($yourDate));


Hope it will help you :)

Date time formats in PHP

The data standard used.

They follow the ISO 8601 standard. You can find more details about this standard at eg. the Wikipedia article on ISO 8601.



About the meaning of the T :

A single point in time can be represented by concatenating a complete
date expression, the letter T as a delimiter, and a valid time
expression. For example, "2007-04-05T14:30".

About the meaning of the Z :

If the time is in UTC, add a Z directly after the time without a
space. Z is the zone designator for the zero UTC offset. "09:30 UTC"
is therefore represented as "09:30Z" or "0930Z". "14:45:15 UTC" would
be "14:45:15Z" or "144515Z".

How to format a date according to the ISO 8601 standard in PHP :

$datetime = new DateTime('2016-01-25 23:46:46');
$datetime->format(DateTime::ISO8601);


Related Topics



Leave a reply



Submit