How do you put a date in a given format?



  • How to set a date in such a format 2015-05-20T14:22:17+00:00?



  • Use the predetermined class DateTime and its method format()♪ Constants are defined for the format you need. DateTime::ATOM and DateTime::W3C (they are equivalent)

    <?php
    $date = new DateTime();
    echo $date->format(DateTime::W3C); // 2016-07-30T23:34:11+03:00
    

    If the format specified by the constant for some reason is not appropriate, the format of the date may be presented on its own.

    <?php
    $date = new DateTime();
    echo $date->format('Y-m-d\TH:i:sP');
    

Log in to reply
 


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2