成人精品一区二区三区中文字幕-成人精品一区二区三区-成人精品一级毛片-成人精品亚洲-日本在线视频一区二区-日本在线视频免费

導航首頁 ? 技術教程 ? PHP:mktime()的用法_Date Time函數
全站頭部文字 我要出現在這里
PHP:mktime()的用法_Date Time函數 817 2023-12-15   

mktime

(PHP 4, PHP 5)

mktime — 取得一個日期的 Unix 時間戳

說明

int 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 ]]]]]]] )

根據給出的參數返回 Unix 時間戳。時間戳是一個長整數,包含了從 Unix 紀元(January 1 1970 00:00:00 GMT)到給定時間的秒數。

參數可以從右向左省略,任何省略的參數會被設置成本地日期和時間的當前值。

注釋

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

秒數(一分鐘之內)。 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 表示不是夏時制,或者 -1(默認值)表示不知道是否是夏時制。如果未知,PHP 會嘗試自己搞明白。這可能產生不可預知(但并非不正確)的結果。如果 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 起,本參數已被廢棄。應該使用新的時區處理特性來替代。

返回值

mktime() 根據給出的參數返回 Unix 時間戳。如果參數非法,本函數返回 FALSE(在 PHP 5.1 之前返回 -1)。

錯誤/異常

在每 次調用日期/時間函數時,如果時區無效則會引發 E_NOTICE 錯誤,如果使用系統設定值或 TZ 環境變量,則會引發 E_STRICTE_WARNING 消息。參見 date_default_timezone_set()。

更新日志

版本 說明 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_STRICTE_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(0, 0, 0, 7, 1, 2000));

// Prints something like: 2006-04-05T01:02:03+00:00
echo date('c', mktime(1, 2, 3, 4, 5, 2006));
?>

Example #2 mktime() 例子

mktime() 在做日期計算和驗證方面很有用,它會自動計算超出范圍的輸入的正確值。例如下面例子中每一行都會產生字符串 "Jan-01-1998"。

<?php
echo date("M-d-Y", mktime(0, 0, 0, 12, 32, 1997));
echo date("M-d-Y", mktime(0, 0, 0, 13, 1, 1997));
echo date("M-d-Y", mktime(0, 0, 0, 1, 1, 1998));
echo date("M-d-Y", mktime(0, 0, 0, 1, 1, 98));
?>

Example #3 下個月的最后一天

任何給定月份的最后一天都可以被表示為下個月的第 "0" 天,而不是 -1 天。下面兩個例子都會產生字符串 "The last day in Feb 2000 is: 29"。

<?php
$lastday = mktime(0, 0, 0, 3, 0, 2000);
echo strftime("Last day in Feb 2000 is: %d", $lastday);
$lastday = mktime(0, 0, 0, 4, -31, 2000);
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 時間戳


主站蜘蛛池模板: 李洋个人资料照片| 李正夏| 预备党员季度思想汇报| 韩国电影《甜性涩爱》| 德鲁| 美女亲热视频| stylistic device| 寇世勋个人资料简介| 尸语者 电视剧| 夕雾| 澳门华侨报| 男生女生向前冲第六季2014| 熊出没免费电影| 戴夫·巴蒂斯塔| 韩版花样男子| 老司机免费在线观看| 浪漫体质| 抖音抖音| 周子航| 新爱情乐园| 福利视频观看| 知否知否应是绿肥红瘦观看| 青春正步走 电视剧| 脚部反射区图解大全高清| 大胆艺术| 天才gogogo综艺节目规则| 胡凯莉| 王渝萱的电影| v我50图片| 小野惠令奈| 五行字库查询表| 姬他演过的电视剧和电影| 宋佳比基尼图片| 荒岛大逃亡电影| 女同恋性吃奶舌吻完整版| 王瑞儿视频| 任港秀| 大世界电影| 安浦清子| 掩护| 影视剧分娩片段合集|

!!!站長長期在線接!!!

網站、小程序:定制開發/二次開發/仿制開發等

各種疑難雜癥解決/定制接口/定制采集等

站長微信:lxwl520520

站長QQ:1737366103