mktime

(PHP 4, PHP 5, PHP 7)

mktime取锟斤拷一锟斤拷锟斤拷锟节碉拷 Unix 时锟斤拷锟�

说锟斤拷

mktime ([ int $hour = date("H") [, int $minute = date("i") [, int $second = date("s") [, int $month = date("n") [, int $day = date("j") [, int $year = date("Y") [, int $is_dst = -1 ]]]]]]] ) : int

锟斤拷锟捷革拷锟斤拷锟侥诧拷锟斤拷锟斤拷锟斤拷 Unix 时锟斤拷锟斤拷锟绞憋拷锟斤拷锟斤拷一锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟剿达拷 Unix 锟斤拷元锟斤拷January 1 1970 00:00:00 GMT锟斤拷锟斤拷锟斤拷锟斤拷时锟斤拷锟斤拷锟斤拷锟斤拷锟�

锟斤拷锟斤拷锟斤拷锟皆达拷锟斤拷锟斤拷锟斤拷省锟皆o拷锟轿猴拷省锟皆的诧拷锟斤拷锟结被锟斤拷锟矫成憋拷锟斤拷锟斤拷锟节猴拷时锟斤拷牡锟角爸碉拷锟�

注锟斤拷

Note:

As of PHP 5.1, when called with no arguments, mktime() throws an E_STRICT notice: use the time() function instead.

锟斤拷锟斤拷

hour

小时锟斤拷锟斤拷 The number of the hour relative to the start of the day determined by month, day and year. Negative values reference the hour before midnight of the day in question. Values greater than 23 reference the appropriate hour in the following day(s).

minute

锟斤拷锟斤拷锟斤拷锟斤拷 The number of the minute relative to the start of the hour. Negative values reference the minute in the previous hour. Values greater than 59 reference the appropriate minute in the following hour(s).

second

锟斤拷锟斤拷锟斤拷一锟斤拷锟斤拷之锟节o拷锟斤拷 The number of seconds relative to the start of the minute. Negative values reference the second in the previous minute. Values greater than 59 reference the appropriate second in the following minute(s).

month

锟铰凤拷锟斤拷锟斤拷 The number of the month relative to the end of the previous year. Values 1 to 12 reference the normal calendar months of the year in question. Values less than 1 (including negative values) reference the months in the previous year in reverse order, so 0 is December, -1 is November, etc. Values greater than 12 reference the appropriate month in the following year(s).

day

锟斤拷锟斤拷锟斤拷 The number of the day relative to the end of the previous month. Values 1 to 28, 29, 30 or 31 (depending upon the month) reference the normal days in the relevant month. Values less than 1 (including negative values) reference the days in the previous month, so 0 is the last day of the previous month, -1 is the day before that, etc. Values greater than the number of days in the relevant month reference the appropriate day in the following month(s).

year

锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟轿伙拷锟斤拷锟轿伙拷锟斤拷郑锟�0-69 锟斤拷应锟斤拷 2000-2069锟斤拷70-100 锟斤拷应锟斤拷 1970-2000锟斤拷锟斤拷锟斤拷锟较低筹拷锟斤拷毡锟斤拷 time_t 锟斤拷为一锟斤拷 32 位锟叫凤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷拢锟�year 锟侥合凤拷锟斤拷围锟斤拷 1901 锟斤拷 2038 之锟戒,锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷 PHP 5.1.0 锟斤拷锟窖憋拷锟剿凤拷锟剿★拷

is_dst

锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷为 1锟斤拷锟斤拷示锟斤拷锟斤拷锟斤拷锟斤拷时锟斤拷时锟戒(DST锟斤拷锟斤拷0 锟斤拷示锟斤拷锟斤拷锟斤拷时锟狡o拷锟斤拷锟斤拷 -1锟斤拷默锟斤拷值锟斤拷锟斤拷示锟斤拷知锟斤拷锟角凤拷锟斤拷锟斤拷时锟狡★拷锟斤拷锟轿粗拷锟絇HP 锟结尝锟斤拷锟皆硷拷锟斤拷锟斤拷锟阶★拷锟斤拷锟斤拷懿锟斤拷锟斤拷锟斤拷锟皆ぶ拷锟斤拷锟斤拷锟斤拷遣锟斤拷锟饺凤拷锟斤拷慕锟斤拷锟斤拷锟斤拷锟� PHP 锟斤拷锟叫碉拷系统锟斤拷锟斤拷锟斤拷锟斤拷 DST 锟斤拷锟斤拷 is_dst 锟斤拷为 1锟斤拷某些时锟斤拷锟斤拷锟斤拷效锟侥★拷锟斤拷锟斤拷 DST 锟斤拷 2:00 锟斤拷效锟斤拷锟斤拷锟斤拷锟叫达拷锟斤拷 2:00 锟斤拷 3:00 之锟斤拷锟绞憋拷涠硷拷锟叫э拷锟�mktime() 锟结返锟斤拷一锟斤拷未锟斤拷锟藉(通锟斤拷为锟斤拷锟斤拷锟斤拷值锟斤拷某些系统锟斤拷锟斤拷锟斤拷 Solaris 8锟斤拷锟斤拷 DST 锟斤拷锟斤拷夜锟斤拷效锟斤拷锟斤拷 DST 锟斤拷效锟斤拷锟斤拷锟� 0:30 锟结被锟斤拷锟斤拷为前一锟斤拷锟� 23:30锟斤拷

Note:

锟斤拷 PHP 5.1.0 锟金,憋拷锟斤拷锟斤拷锟窖憋拷锟斤拷锟斤拷锟斤拷应锟斤拷使锟斤拷锟铰碉拷时锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟�

Note:

PHP 7.0.0 锟金,此诧拷锟斤拷锟窖撅拷锟斤拷锟狡筹拷锟斤拷

锟斤拷锟斤拷值

mktime() 锟斤拷锟捷革拷锟斤拷锟侥诧拷锟斤拷锟斤拷锟斤拷 Unix 时锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟角凤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷 FALSE锟斤拷锟斤拷 PHP 5.1 之前锟斤拷锟斤拷 -1锟斤拷锟斤拷

锟斤拷锟斤拷锟届常

锟斤拷每 锟轿碉拷锟斤拷锟斤拷锟斤拷/时锟戒函锟斤拷时锟斤拷锟斤拷锟绞憋拷锟斤拷锟叫э拷锟斤拷锟斤拷锟斤拷 E_NOTICE 锟斤拷锟斤拷锟斤拷锟绞癸拷锟较低筹拷瓒ㄖ碉拷锟� TZ 锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟� E_STRICT 锟斤拷 E_WARNING 锟斤拷息锟斤拷锟轿硷拷 date_default_timezone_set()锟斤拷

锟斤拷锟斤拷锟斤拷志

锟芥本 说锟斤拷
7.0.0 is_dst锟斤拷锟斤拷锟窖撅拷锟斤拷锟狡筹拷锟斤拷
5.3.0 mktime() now throws E_DEPRECATED notice if the is_dst parameter is used.
5.1.0 is_dst 锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷时锟斤拷锟斤拷锟斤拷锟斤拷 FALSE 锟斤拷锟斤拷锟斤拷锟斤拷 -1锟斤拷锟斤拷锟斤拷锟剿憋拷锟斤拷锟斤拷锟斤拷锟皆斤拷锟斤拷锟斤拷锟斤拷锟秸诧拷锟斤拷全为锟姐。
5.1.0 When called with no arguments, mktime() throws E_STRICT notice. Use the time() function instead.
5.1.0

锟斤拷锟节凤拷锟斤拷 E_STRICT 锟斤拷 E_NOTICE 时锟斤拷锟斤拷锟斤拷

锟斤拷锟斤拷

Example #1 锟斤拷锟斤拷锟斤拷锟斤拷

<?php
// Set the default timezone to use. Available as of PHP 5.1
date_default_timezone_set('UTC');

// Prints: July 1, 2000 is on a Saturday
echo "July 1, 2000 is on a " date("l"mktime(000712000));

// Prints something like: 2006-04-05T01:02:03+00:00
echo date('c'mktime(123452006));
?>

Example #2 mktime() 锟斤拷锟斤拷

mktime() 锟斤拷锟斤拷锟斤拷锟节硷拷锟斤拷锟斤拷锟街わ拷锟斤拷锟斤拷锟斤拷锟矫o拷锟斤拷锟斤拷锟皆讹拷锟斤拷锟姐超锟斤拷锟斤拷围锟斤拷锟斤拷锟斤拷锟斤拷锟饺分碉拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟矫恳伙拷卸锟斤拷锟斤拷锟斤拷锟街凤拷锟斤拷 "Jan-01-1998"锟斤拷

<?php
echo date("M-d-Y"mktime(00012321997));
echo 
date("M-d-Y"mktime(0001311997));
echo 
date("M-d-Y"mktime(000111998));
echo 
date("M-d-Y"mktime(0001198));
?>

Example #3 锟铰革拷锟铰碉拷锟斤拷锟揭伙拷锟�

锟轿何革拷锟斤拷锟铰份碉拷锟斤拷锟揭伙拷於硷拷锟斤拷员锟斤拷锟绞疚拷赂锟斤拷碌牡锟� "0" 锟届,锟斤拷锟斤拷锟斤拷 -1 锟届。锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟接讹拷锟斤拷锟斤拷锟斤拷址锟斤拷锟� "The last day in Feb 2000 is: 29"锟斤拷

<?php
$lastday 
mktime(000302000);
echo 
strftime("Last day in Feb 2000 is: %d"$lastday);
$lastday mktime(0004, -312000);
echo 
strftime("Last day in Feb 2000 is: %d"$lastday);
?>

注锟斤拷

Caution

锟斤拷 PHP 5.1.0 之前锟斤拷锟斤拷锟轿猴拷锟斤拷知 Windows 锟芥本锟皆硷拷一些锟斤拷锟斤拷系统锟铰诧拷支锟街革拷锟斤拷时锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷莸锟斤拷锟叫э拷锟轿э拷锟斤拷锟轿� 1970 锟斤拷 2038锟斤拷

锟轿硷拷

  • checkdate() - 锟斤拷证一锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟�
  • gmmktime() - 取锟斤拷 GMT 锟斤拷锟节碉拷 UNIX 时锟斤拷锟�
  • date() - 锟斤拷式锟斤拷一锟斤拷锟斤拷锟斤拷时锟戒/锟斤拷锟斤拷
  • time() - 锟斤拷锟截碉拷前锟斤拷 Unix 时锟斤拷锟�