Home  >  Article  >  Backend Development  >  Summary of usage of php timestamp function

Summary of usage of php timestamp function

WBOY
WBOYOriginal
2016-07-25 08:52:581421browse
  1. strtotime(”2009-1-22″)
  2. echo strtotime(”2009-1-22″) Result: 1232553600
Copy code

Instructions: Return to 0:00 on January 22, 2009 Minutes 0 seconds timestamp

Second, the php timestamp function obtains the English text date and time For easy comparison, use date to convert the current timestamp and the specified timestamp into system time

1) Print the timestamp at this time tomorrow strtotime(”+1 day”)

  1. //Convert timestamp to date
  2. $date_time_array = getdate(1297845628); //1311177600 1316865566
  3. $hours = $date_time_array["hours"];
  4. $minutes = $date_time _array[" minutes"];
  5. $seconds = $date_time_array["seconds"];
  6. $month = $date_time_array["mon"];
  7. $day = $date_time_array["mday"];
  8. $year = $date_time_array["year" ];
  9. echo "year:$yearnmonth:$monthnday:$daynhour:$hoursnminutes:$minutesnseconds:$secondsn";
  10. //Convert normal date to timestamp
  11. echo mktime(0, 0, 0, 9, 18, 2011) . "n";
  12. echo mktime(0, 0, 0, 9, 25, 2011) . "n";
  13. /*
  14. time();
  15. is to get the current time, but it is an integer
  16. */
  17. //You can format this
  18. echo "time() displays the year, month, day, hour, minute and second:" . date("Y-m-d H:i:s", time()) . "n";
  19. // In this way, the hours, minutes and seconds are displayed together
  20. echo "time() only displays the year, month and day:" . date("Y-m-d ", time()) . "n"; //Only the year, month and day are displayed
  21. echo "Time Stamp formatting: " . date("Y-m-d H:i:s", 1297845628) . "n"; //Use timestamp directly
  22. /* vim: set ts=4 sw=4 sts=4 tw=100 noet : */
  23. ?>
Copy code


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