Home > Backend Development > PHP Tutorial > Analysis of examples of using mktime in php to obtain timestamps

Analysis of examples of using mktime in php to obtain timestamps

WBOY
Release: 2016-07-25 09:05:32
Original
1134 people have browsed it
  1. $now = mktime(0,0,0,date("m"),date("d"),date("Y"));
  2. echo "now is ". date("Y/m/d", $now);
Copy the code

Display the results: now is 2012/05/30 Obviously this is not the result I want. So, according to the old thinking, it was naturally transformed into the following form:

  1. $now = mktime(date("h"),date("M"),date("s"),date("m"),date("d") ,date("Y"));
  2. echo "now is ".date("Y/M/d h:i:s", $now);
Copy code

Pay attention to the red part, usually if the month Use m, then the minute should be M. Or use M for the former and m for the latter. Show results: Warning: mktime() expects parameter 2 to be long, string given in D:usrwebroottestPHPindex.php on line 46 now is 1970/01/01 08:Jan:00

The correct answer is this:

  1. $now = mktime(date("h"),date("i"),date("s"),date("m"),date("d") ,date("Y"));
  2. echo "now is ".date("Y/m/d h:i:s", $now);
Copy code

haha~ It's "i" instead of What is m or M? I am giving you this example just to save beginners of PHP from taking some detours. As for what M means, smart person, you will definitely understand. Show results: now is 2012/05/30 04:54:25

>>>> Articles you may be interested in: Detailed explanation of the differences between time(), date(), and mktime() in php Analysis of the difference between time() and mktime() usage in php Y2K38 vulnerability of strtotime() and mktime() in php 2038 issue



source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template