Home  >  Article  >  Backend Development  >  Detailed explanation of the differences between time(), date(), and mktime() in php

Detailed explanation of the differences between time(), date(), and mktime() in php

WBOY
WBOYOriginal
2016-07-25 08:56:201108browse
  1. print(date( "l dS of F Y h:i:s A" ));
  2. print("July 1, 2000 is on a " . date("l", mktime(0 ,0,0,7,1,2000)));
  3. ?>
Copy code

Example 2:

  1. $tomorrow = mktime(0,0,0,date("m") ,date("d")+1,date("Y"));
  2. $lastmonth = mktime (0,0,0,date("m")-1,date("d"), date("Y"));
  3. $nextyear = mktime(0,0,0,date("m"), date("d", date("Y")+1);
  4. ?>
Copy code

Reference gmdate() mktime()

strftime Format the server's time locally. Syntax: string strftime(string format, int [timestamp]); Return value: string Function type: time date Content Description The string of the return value is determined by the configured format. If there is a timestamp value passed in, the timestamp will be formatted and returned; if there is no timestamp value passed in, the time of the current server will be formatted locally and returned. The month or day of the week name changes depending on the locale configuration setlocale(). The returned string can be in the following format:

  1. setlocale ("LC_TIME", "C");
  2. print(strftime("%A in Finnish is "));
  3. setlocale ("LC_TIME", "fi");
  4. print(strftime("%A, in French "));
  5. setlocale ("LC_TIME", "fr");
  6. print(strftime("%A and in German "));
  7. setlocale ("LC_TIME", "de ");
  8. print(strftime("%A.n"));
  9. ?>
Copy code

Refer to setlocale() mktime()

getdate Get time and date information. Syntax: array getdate(int timestamp); Return value: array Function type: time date Content Description The elements of the returned array include the following items:

"seconds" - seconds "minutes" - minutes "hours" - hours "mday" - the day of the month "wday" - the day of the week "mon" - month number "year" - year, number "yday" - the day of the year; such as: "299" "weekday" - the full name of the day of the week; e.g.: "Friday" "month" - the full name of the month; such as: "January"

gettimeofday Get the current time. Syntax: array gettimeofday(void); Return value: array Function type: time date Content Description The elements of the returned array include the following items:

"sec" - seconds "usec" - millionths of a second "minuteswest" - Minutes in Greenwich Mean Time "dsttime" - the destination time zone

gmdate Get the current time difference from GMT. Syntax: string gmdate(string format, int timestamp); Return value: string Function type: time date Content Description This function is similar to the date() function, except that this function returns the time difference from Greenwich Mean Time (GMT) 1 2 Next page Last page



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