How do I get the current date and time in PHP?

后端 未结 30 2354
孤城傲影
孤城傲影 2020-11-22 08:19

Which PHP function can return the current date/time?

30条回答
  •  闹比i
    闹比i (楼主)
    2020-11-22 08:45

    // Set the default timezone to use. Available since PHP 5.1
    date_default_timezone_set('UTC');
    
    
    // Prints something like: Monday
    echo date("l");
    
    // Prints something like: Monday 8th of August 2016 03:12:46 PM
    echo date('l jS \of F Y h:i:s A');
    
    // Prints: July 1, 2016 is on a Saturday
    echo "July 1, 2016 is on a " . date("l", mktime(0, 0, 0, 7, 1, 2016));
    
    /* Use the constants in the format parameter */
    // Prints something like: Wed, 25 Sep 2013 15:28:57 -0700
    echo date(DATE_RFC2822);
    
    // Prints something like: 2016-07-01T00:00:00+00:00
    echo date(DATE_ATOM, mktime(0, 0, 0, 7, 1, 2000));
    

提交回复
热议问题