NOW() function in PHP

前端 未结 20 1721
遥遥无期
遥遥无期 2020-11-28 17:26

Is there a PHP function that returns the date and time in the same format as the MySQL function NOW()?

I know how to do it using date(), b

20条回答
  •  青春惊慌失措
    2020-11-28 17:44

    Or you can use DateTime constants:

    echo date(DateTime::W3C); // 2005-08-15T15:52:01+00:00
    

    Here's the list of them:

    ATOM = "Y-m-d\TH:i:sP" ;               // -> 2005-08-15T15:52:01+00:00
    COOKIE = "l, d-M-Y H:i:s T" ;          // -> Monday, 15-Aug-2005 15:52:01 UTC
    ISO8601 = "Y-m-d\TH:i:sO" ;            // -> 2005-08-15T15:52:01+0000
    RFC822 = "D, d M y H:i:s O" ;          // -> Mon, 15 Aug 05 15:52:01 +0000
    RFC850 = "l, d-M-y H:i:s T" ;          // -> Monday, 15-Aug-05 15:52:01 UTC
    RFC1036 = "D, d M y H:i:s O" ;         // -> Mon, 15 Aug 05 15:52:01 +0000
    RFC1123 = "D, d M Y H:i:s O" ;         // -> Mon, 15 Aug 2005 15:52:01 +0000
    RFC2822 = "D, d M Y H:i:s O" ;         // -> Mon, 15 Aug 2005 15:52:01 +0000
    RFC3339 = "Y-m-d\TH:i:sP" ;            // -> 2005-08-15T15:52:01+00:00 ( == ATOM)
    RFC3339_EXTENDED = "Y-m-d\TH:i:s.vP" ; // -> 2005-08-15T15:52:01.000+00:00
    RSS = "D, d M Y H:i:s O" ;             // -> Mon, 15 Aug 2005 15:52:01 +0000
    W3C = "Y-m-d\TH:i:sP" ;                // -> 2005-08-15T15:52:01+00:00
    

    For debugging I prefer a shorter one though (3v4l.org):

    echo date('ymd\THisP'); // 180614T120708+02:00
    

提交回复
热议问题