How to convert date time to ISO 8601 format in PHP?

0

I have the following format: 2018-10-23T12:05:18.18UTC0TUE

I need to convert to 2013-06-28T08:54:00.000-03:00 (format iso 8601).

Is there anything specific in php that will help me make this datetime?

What would this 000-03:00 be?

    
asked by anonymous 31.10.2018 / 20:41

1 answer

3

Simply start the constructor of DateTime by passing its string as a parameter:

$date = new DateTime('2018-10-23T12:05:18.18UTC0TUE')

And use the method DateTime::format to format in ISO8601

$date->format(DateTime::ISO8601);

You can use the date function too:

date(DATE_ISO8601, strtotime('2018-10-23T12:05:18.18UTC0TUE'))
  

What would this 000-03:00 be?

000-03:00 are actually two things together. 000 is the end of the milliseconds of your date.

-03:00 already refers to the timezone of your date.

If you use the DateTime::getTimezone() function, you can get the object DateTimezone of your date.

See:

$date->getTimezone();

The result is:

DateTimeZone Object
(
    [timezone_type] => 3
    [timezone] => UTC
)

According to the Wikipedia :

  

[...] is the reference time zone from which all other time zones in the world are calculated.

Check out some date formatting constants in documentation

    
31.10.2018 / 21:01