In the actual work we also need to often use the specified time to generate
For example, you need to find a registered user yesterday to this moment.
We need to do two things:
- Gets the current time of the Unix timestamp. Use the time () function to directly handle
- So how did you generate the time you specified yesterday? This is the time we need to use
mktime()函数
. Abbreviation: Make time.
The best time to generate is a UNIX timestamp. Because it is January 1, 1970 0 o'clock to the present time. We make an interval judgment, the user registered yesterday to today by the time filter out.
Our Mktime () function can obtain a localized timestamp for a date and time. Its syntax format is as follows:
int mktime (int $hour [, int $minute [, int $second [, int $month [, int $day [. int$year [, int $.is_dstl.l}] [31]
The parameters of the function are: hours, minutes, seconds, months, days, years, daylight saving time. When using this function, it is important to note that the parameters listed are the same as the parameters of the function. For example, the following code implements the ability to construct a timestamp with mktime.
<?php
echo mktime (13,15,30,8,18,2014);
?>
The return result of the Mktime function is a UNIX timestamp that does not mean much to the user, and is often done with the date function to convert the time.
For example, the following code implements the operation of the time:
<?php
echo date ( "m-d-y h:m:s" "\ n"
echo date ( "m-d-y h:m:s" mktime ( 10 15 Span class= "pun", 35 date Span class= "pun" > ( "M" date Span class= "pun" > ( "D" date Span class= "pun" > ( "Y" "\ n"
echo date("m-d-Y h:m:s",mktime(10,15,35,date("m"),date("d")-30,date("Y")))."\n";
?>
When we use it, we often need to use another function: Strtotime ().
Its syntax format is as follows:
int Strtotime (string $time [, int $now = time ()])
It can parse the date-time description of the English text into a Unix timestamp.
Parameters:
- Time to pass in a string
- The optional parameter is whether to pass in the Unix timestamp, or the current UNIX timestamp if not passed.
Let's experiment and look at some of the examples provided in the manual:
<?php
//now为现在的当前时间
echo strtotime("now")."<br />";
//2000年9月10日
echo strtotime("10 September 2000")."<br />";
//当前时间加一天
echo strtotime("+1 day")."<br />";
//当前时间加一周
echo strtotime("+1 week")."<br />";
//当前时间加一周2天4小时2秒
echo strtotime("+1 week 2 days 4 hours 2 seconds")."<br />";
//下一个星期四
echo strtotime("next Thursday")."<br />";
//上一个星期一
echo strtotime("last Monday")."<br />";
?>
Getting Started with PHP -022-key date function get localization timestamp function. MD