Convert datetime to RFC 3339

前端 未结 3 1692
甜味超标
甜味超标 2021-02-19 17:52

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?

相关标签:
3条回答
  • 2021-02-19 18:29

    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);
    
    0 讨论(0)
  • 2021-02-19 18:37

    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 
    
    0 讨论(0)
  • 2021-02-19 18:52

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

    date(DATE_RFC3339);
    

    and

    date(DATE_ATOM);
    

    return an RFC3339 formatted date time string and are the equivalent of:

    date('Y-m-d\TH:i:sP');
    
    0 讨论(0)
提交回复
热议问题