Home  >  Article  >  Backend Development  >  PHP introductory tutorial (21) PHP date and time functions

PHP introductory tutorial (21) PHP date and time functions

WBOY
WBOYOriginal
2016-07-25 08:55:45929browse
  1. echo time(); // return "1264668961"
  2. ?>
Copy code

2, date()

To convert a UNIX timestamp into a readable current time, use the date() function.

The prototype of the date function is as follows:

  1. echo date("Y/m/d");
  2. echo "
    ";
  3. echo date("Y.m.d");
  4. echo "
    ";
  5. echo date("Y-m-d");
  6. ?>
Copy code

output: 2013/11/21 2013.11.21 2013-11-21

3, mktime() The mktime() function returns the Unix timestamp of a date.

Parameter description:

  1. echo(date("M-d-Y",mktime(0,0,0,12,36,2001)));
  2. echo(date("M-d-Y",mktime(0,0 ,0,14,1,2001)));
  3. echo(date("M-d-Y",mktime(0,0,0,1,1,2001)));
  4. echo(date("M-d-Y",mktime(0 ,0,0,1,1,99)));
  5. ?>
Copy code

output: Jan-05-2002 Feb-01-2002 Jan-01-2001 Jan-01-1999 4.checkdate() The checkdate() function verifies a Gregorian date. The function returns true if the specified value is legal, false otherwise. Dates are legal if: month is between and including 1 - 12 The value of Day is within the range of days that a given month should have, taking leap years into account. year is between and including 1 to 32767 grammar checkdate(month,day,year) parameter

  1. var_dump(checkdate(12,31,2000));
  2. var_dump(checkdate(2,29,2003));
  3. var_dump(checkdate(2,29,2004));
  4. ?>
Copy code

output: bool(true) bool(false) bool(true)

>> View more php introductory tutorials



Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn