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

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

strtotime

(PHP 4, PHP 5)

strtotime — 將任何英文文本的日期時間描述解析為 Unix 時間戳

說明

int strtotime ( string $time [, int $now = time() ] )

本函數預期接受一個包含美國英語日期格式的字符串并嘗試將其解析為 Unix 時間戳(自 January 1 1970 00:00:00 GMT 起的秒數),其值相對于 now 參數給出的時間,如果沒有提供此參數則用系統當前時間。

本函數將使用 TZ 環境變量(如果有的話)來計算時間戳。自 PHP 5.1.0 起有更容易的方法來定義時區用于所有的日期/時間函數。此過程在 date_default_timezone_get() 函數頁面中有說明。

參數

time

日期/時間字符串。正確格式的說明詳見 日期與時間格式。

now

用來計算返回值的時間戳。

返回值

成功則返回時間戳,否則返回 FALSE。在 PHP 5.1.0 之前本函數在失敗時返回 -1。

錯誤/異常

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

更新日志

版本 說明 5.3.0 在 PHP 5.3.0 之前, 24:00 不是一個有效的格式,并且 strtotime() 會返回 FALSE。 5.2.7 In PHP 5 prior to 5.2.7, requesting a given occurrence of a given weekday in a month where that weekday was the first day of the month would incorrectly add one week to the returned timestamp. This has been corrected in 5.2.7 and later versions. 5.1.0 失敗時返回 FALSE,不再是 -1。 5.1.0

現在發布 E_STRICTE_NOTICE 時區錯誤。

5.0.2 在 PHP 5 中到 5.0.2 之前,"now" 和其它相對時間從今天午夜起錯誤計算了。這和正確從當前時間起計算的其它版本不同。 5.0.0 Microseconds began to be allowed, but they are ignored. 4.4.0 在 PHP 4.4 之前,"next" 被錯誤計算為 +2。對此通常的解決方法是用 "+1"。

范例

Example #1 strtotime() 例子

<?php
echo strtotime("now"), "n";
echo strtotime("10 September 2000"), "n";
echo strtotime("+1 day"), "n";
echo strtotime("+1 week"), "n";
echo strtotime("+1 week 2 days 4 hours 2 seconds"), "n";
echo strtotime("next Thursday"), "n";
echo strtotime("last Monday"), "n";
?>

Example #2 失敗檢查

<?php
$str = 'Not Good';

// previous to PHP 5.1.0 you would compare with -1, instead of false
if (($timestamp = strtotime($str)) === false) {
    echo "The string ($str) is bogus";
} else {
    echo "$str == " . date('l dS of F Y h:i:s A', $timestamp);
}
?>

注釋

Note:

如果給定的年份是兩位數字的格式,則其值 0-69 表示 2000-2069,70-100 表示 1970-2000。 See the notes below for possible differences on 32bit systems (possible dates might end on 2038-01-19 03:14:07).

Note:

有效的時間戳通常從 Fri, 13 Dec 1901 20:45:54 GMT 到 Tue, 19 Jan 2038 03:14:07 GMT(對應于 32 位有符號整數的最小值和最大值)。不是所有的平臺都支持負的時間戳,那么日記范圍就被限制為不能早于 Unix 紀元。這意味著在 1970 年 1 月 1 日之前的日期將不能用在 Windows,一些 Linux 版本,以及幾個其它的操作系統中。不過 PHP 5.1.0 及更新的版本克服了此限制。

For 64-bit versions of PHP, the valid range of a timestamp is effectively infinite, as 64 bits can represent approximately 293 billion years in either direction.

Note:

Dates in the m/d/y or d-m-y formats are disambiguated by looking at the separator between the various components: if the separator is a slash (/), then the American m/d/y is assumed; whereas if the separator is a dash (-) or a dot (.), then the European d-m-y format is assumed.

To avoid potential ambiguity, it's best to use ISO 8601 (YYYY-MM-DD) dates or DateTime::createFromFormat() when possible.

Note:

Using this function for mathematical operations is not advisable. It is better to use DateTime::add() and DateTime::sub() in PHP 5.3 and later, or DateTime::modify() in PHP 5.2.

參見

Date and Time Formats DateTime::createFromFormat() - Returns new DateTime object formatted according to the specified format checkdate() - 驗證一個格里高里日期 strptime() - 解析由 strftime 生成的日期/時間


主站蜘蛛池模板: 大家都在搜| 玛丽·杜布瓦| 卫星掉落| 毕业论文3000字范文| 创业史全文阅读| 自拍在线播放| 古装发型| 张俪床戏| 唐朝浪漫英雄| 假期有收获教学设计| 让我听懂你的语言歌词| 热血番| 生活片情感大片大全| 红电视剧演员表| 二手家具转让| 迷失之城剧情介绍| 闲章内容大全图片 | 马路虫子图片| call me by your name电影| 茶馆妈妈韩剧| 罗中立的《父亲》详案| 龟兔赛跑的故事视频| .和平精英| 尹馨演过的三部电影| 母女大战| 小虎队《爱》歌词| superstar电影在线播放| 欧美视频亚洲视频| 天地姻缘七仙女演员表| 电视剧《后浪》| 好看女生头像| 湖北卫视在线直播| 二年级上册期末真题卷| 营业执照注销打什么电话咨询| 红灯区1996| 爱爱内含光在线播放| 白鹿罗云熙| 韩义生| 全蚀狂爱| 《魔鬼天使》电影| 口加一笔变新字有几个|

!?。≌鹃L長期在線接?。。?/p>

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

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

站長微信:lxwl520520

站長QQ:1737366103