My input date is 2014-03-10 05:40:00
. How can I convert it to RFC format like 2014-3-10T05:40:00.000-00:00
?
Asked
Active
Viewed 3.3k times
19

Mark Amery
- 143,130
- 81
- 406
- 459

Sadikhasan
- 18,365
- 21
- 80
- 122
3 Answers
30
here another option added in php5 like this
$datetime= date("c", strtotime("2014-03-10 05:40:00"));
echo $datetime; //Output : 2014-03-10T05:40:00+00:00

Sadikhasan
- 18,365
- 21
- 80
- 122
26
RFC3339 is one of the predefined format constants of the DateTime
class.
$inputDate = "2014-03-10 05:40:00";
$datetime = \DateTime::createFromFormat("Y-m-d H:i:s", $inputDate);
echo $datetime->format(\DateTime::RFC3339);

Adam Elsodaney
- 7,722
- 6
- 39
- 65
16
I'd like to add that the predefined constants for this can also be used with date()
. All of these:
date(DATE_RFC3339);
date(DATE_ATOM);
date(DATE_W3C);
return an RFC3339 formatted date time string and are the equivalent of:
date('Y-m-d\TH:i:sP');

But those new buttons though..
- 21,377
- 10
- 81
- 108