Converting Date and Time to RFC 3339

My input date 2014-03-10 05:40:00. How to convert it to RFC format, for example 2014-3-10T05:40:00.000-00:00?

+4
source share
3 answers

here in php5 added another option similar to this

$datetime= date("c", strtotime("2014-03-10 05:40:00"));
echo $datetime;  //Output : 2014-03-10T05:40:00+00:00 
+15
source

RFC3339 is one of the predefined class format constantsDateTime .

$inputDate = "2014-03-10 05:40:00";

$datetime = \DateTime::createFromFormat("Y-m-d H:i:s", $inputDate);

echo $datetime->format(\DateTime::RFC3339);
+12
source

I would like to add that predefined constants for this can also be used with date(). Both:

date(DATE_RFC3339);

and

date(DATE_ATOM);

returns an RFC3339 formatting date date string and is equivalent to:

date('Y-m-d\TH:i:sP');
+7
source

Source: https://habr.com/ru/post/1530947/


All Articles