搜尋
首頁後端開發php教程tonight i feel close to you PHP strtotime函數詳解

先看手冊介紹:
strtotime — 將任何英文文本的日期時間描述解析為Unix 時間戳
格式:int strtotime ( string $time [, int $now ] )
  本函數預期接受一個包含美國英語日期格式的字串並嘗試將其解析為Unix 時間戳記(自January 1 1970 00:00:00 GMT 起的秒數),其值相對於now 參數給出的時間,如果沒有提供此參數則用系統當前時間。
  本函數將使用 TZ 環境變數(如果有的話)來計算時間戳記。自 PHP 5.1.0 起有更容易的方法來定義時區用於所有的日期/時間函數。此程序在 date_default_timezone_get() 函數頁面中有說明。
Note : 如果給定的年份是兩位數字的格式,則其值 0-69 表示 2000-2069,70-100 表示 1970-2000。
參數
time
被解析的字串,格式依據 GNU » 日期輸入格式 的語法。在 PHP 5.0 之前,time 中不允許有毫秒數,自 PHP 5.0 起可以有但是會被忽略掉。
now
用來計算回傳值的時間戳記。 這個參數預設值是當前時間time(),也可以設定為其他時間的時間戳記(我一直忽略的一個功能啊,慚愧)
回傳值: 成功則回傳間戳,否則傳回 FALSE 。在PHP 5.1.0 之前本函數在失敗時傳回-1,後面版本回傳false.
  strtotime的第一個參數可以是我們常見的英文時間格式,例如「2008-8-20」或「10 September 2000 」等等。也可以是以參數now為基準的時間描述,例如「+1 day」等等。
以下是後一種方式的可使用參數清單,其中「當前時間」是指strtotime第二個參數now的值,預設為當前時間
1.月,日英文名及其常用縮寫清單:
january,february,march,april,may,june,july,august,september,sept,october,november,december,
sunday,monday,tuesday,tues,wednesday,wednes,>sunday,monday,tuesday,tues,wednesday,wednes,thursday,thur,monday ,friday,saturday
2.時間參數與和平描述:
am : the time is before noon 上午
pm : the time is noon or later 下午
year: one year; for example, 「next year」 年,如「next year」代表明年
month : one month; for example, 「last month」 月,如「last month」代表上一月
fortnight : two weenight; for exampleks; for example, 「a fortnight ago」 兩週,如「a fortnight ago」代表兩週前
week : one week 週
day: a day 天
hour: an hour 小時
minute 天
hour: an hour 小時
minute 天
hour: 分鐘
min : same as minute 同「minute」
second : a second 秒
sec : same as second 同「second」
3.相關與順序說明:
+n/-n :以當前時間算,加個減指定的時間,例如”+1 hour”是指當前時間加一小時
ago :time relative to now; such as “24 hours ago”  以當前時間往前算,例如」24 hours ago」代表「24小時前」
tomorrow : 24 hours later than the current date and time 以當前時間(包括日期和時間)為標準,明天同一時間
yesterday : 24 hours earlier thanurs earlier thanurs the current date and time 以當前時間(包括日期和時間)為標準,昨天同一時間
today : the current date and time 當前時間(包括日期和時間)
now : the current date and time 當前時間(包括日期和時間)
last : modifier meaning “the preceding”; for example, “last tuesday” 代表“上一個”,例如“last tuesday”代表“上週二同一時間”
this : the given time during the current day or the next occurrence of the given time; for example, “this 7am” gives the timestamp for 07:00 on the current day, while “this week” gives the timestamp for rent wtime the current的指定時間或下面一個時段的時間戳,例如「this 7am」給出當天7:00的時間戳,而「this week」給出的是從當前時間開始的一整週的時間戳,也就是目前時間(經本人測試:strtotime('this week')=strtotime('now'));
next : modifier meaning the current time value of the subject plus one; for example, “next hour” 當前時間加上指定的時間,例如「next hour」是指當前時間加上一小時,即加3600
//先到這,下面的還沒時間翻譯
first : ordinal modifier, esp. for months; for example, “May first” (actually, it's just the same as next)
third : see first (note that there is no “second” for ordinality, since that would conflict with the second time value) fifth : see first
sixth : see first
seventh : see first
eighth : see first
seventh : see first
eighth : see first
ninth : see first see first
twelfth : see first
4.時區描述:
gmt : Greenwich Mean Time
ut : Coordinated Universal Time
utc : same as peut bst : British Summer Time
wat : West Africa Time
at : Azores Time
ast : Atlantic Standard Time
adt : Atlantic Daylight
est : 東: Eastern Daylight Time
cst : Central Standard Time
cdt : Central Daylight Time
mst : Mountain Standard Time
mdt : Mountain Daylight Time
pst : Pacific Standard
Timepdt :> Timepdt : Daylight Time
yst : Yukon Standard Time
ydt : Yukon Daylight Time
hst : Hawaii Standard Time
hdt : Hawaii Daylight Time
cat : Central Alaska
Timeakst : Akaka;
akdt : Alaska Daylight Time
ahst : Alaska-Hawaii Standard Time
nt : Nome Time
idlw : International Date Line West
cet : Central European
mewt : Middle European Winter Time
mest : Middle European Summer Time
mesz : Middle European Summer Time
swt : Swedish Winter Time
sst : Swedish> Time Timefwt : Time
fst : French Summer Time
eet : Eastern Europe Time, USSR Zone 1
bt : Baghdad Time, USSR Zone 2
zp4 : USSR Zone 3
zp5 : >zp6 : USSR Zone 5
wast : West Australian Standard Time
wadt : West Australian Daylight Time
cct : China Coast Time, USSR Zone 7
jst : Japan Standard Time,,,SR ZSRone 8
east : Eastern Australian Standard Time
eadt : Eastern Australian Daylight Time
gst : Guam Standard Time, USSR Zone 9
nzt : New Zealand Time
nzst : New Zealand Standard Time nzst. New Zealand Daylight Time
idle : International Date Line East
在PHP中有個叫做strtotime的函數。 strtotime 實作功能:取得某個日期的時間戳,或取得某個時間的時間戳記。strtotime 將任何英文文本的日期時間描述解析為Unix時間戳[將系統時間轉換成unix時間戳]
一,取得指定日期的unix時間戳
strtotime("2009-1-22") 範例如下:
1.echo strtotime("2009-1-22")
結果:1232553600
說明:回傳2009年1月22日0點0分0秒時間戳
二,取得2009年1月22日0點0分0秒時間戳
二,取得英文文字日期時間
範例如下:
方便比較,使用date將當時間戳與指定時間戳轉換成系統時間
(1)列印明天此時的時間戳strtotime("+1 day" )
目前時間:
1.echo date("Y-m-d H:i:s",time())
結果:2009-01-22 09:40:25
指定時間:
1.echo date("Y-m-d H:i:s",strtotime("+1 day"))
結果:2009-01-23 09:40:25
(2)列印昨天此時的時間戳strtotime("-1 day")
當前時間:
1.echo date("Y-m-d H:i:s",time())
結果:2009-01-22 09: 40:25
指定時間:
1.echo date("Y-m-d H:i:s",strtotime("-1 day"))
結果:2009-01-21 09:40:25
(3)列印下個星期此時的時間戳strtotime("+1 week")
當前時間:
1.echo date("Y-m-d H:i:s",time())
結果:2009-01-22 09:40:25
指定時間:
1.echo date("Y-m-d H:i:s",strtotime("+1 week"))
結果:2009-01-29 09:40:25
(4)列印上個星期此時的時間戳strtotime("-1 week")
當前時間:
1.echo date(" Y-m-d H:i:s",time())
結果:2009-01-22 09:40:25
指定時間:
1.echo date("Y-m-d H:i:s", strtotime("-1 week"))
結果:2009-01-15 09:40:25
(5)列印指定下週幾的時間戳strtotime("next Thursday")
當前時間:
1.echo date("Y-m-d H:i:s",time())
結果:2009-01-22 09:40:25
指定時間:
1.echo date ("Y-m-d H:i:s",strtotime("next Thursday"))
結果:2009-01-29 00:00:00
(6)列印指定上星期幾的時間戳strtotime(" last Thursday")
目前時間:
1.echo date("Y-m-d H:i:s",time())
結果:2009-01-22 09:40:25
指定時間:
1.echo date("Y-m-d H:i:s",strtotime("last Thursday"))
結果:2009-01-15 00:00:00
以上範例可知,strtotime能將任何英文文本的日期時間描述解析為Unix時間戳,我們結合mktime()或date()格式化日期時間取得指定的時間戳,實現所需的日期時間。

希望通過本文的介紹後,你已經能掌握strtotime函數用法。

以上就介紹了tonight i feel close to you PHP strtotime函數詳解,包括了tonight i feel close to you方面的內容,希望對PHP教程有興趣的朋友有所幫助。

陳述
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
高流量網站的PHP性能調整高流量網站的PHP性能調整May 14, 2025 am 12:13 AM

TheSecretTokeEpingAphp-PowerEdwebSiterUnningSmoothlyShyunderHeavyLoadInVolvOLVOLVOLDEVERSALKEYSTRATICES:1)emplactopCodeCachingWithOpcachingWithOpCacheToreCescriptexecution Time,2)使用atabasequercachingCachingCachingWithRedataBasEndataBaseLeSendataBaseLoad,3)

PHP中的依賴注入:初學者的代碼示例PHP中的依賴注入:初學者的代碼示例May 14, 2025 am 12:08 AM

你應該關心DependencyInjection(DI),因為它能讓你的代碼更清晰、更易維護。 1)DI通過解耦類,使其更模塊化,2)提高了測試的便捷性和代碼的靈活性,3)使用DI容器可以管理複雜的依賴關係,但要注意性能影響和循環依賴問題,4)最佳實踐是依賴於抽象接口,實現鬆散耦合。

PHP性能:是否可以優化應用程序?PHP性能:是否可以優化應用程序?May 14, 2025 am 12:04 AM

是的,優化papplicationispossibleandessential.1)empartcachingingcachingusedapcutorediucedsatabaseload.2)優化的atabaseswithexing,高效Quereteries,and ConconnectionPooling.3)EnhanceCodeWithBuilt-unctions,避免使用,避免使用ingglobalalairaiables,並避免使用

PHP性能優化:最終指南PHP性能優化:最終指南May 14, 2025 am 12:02 AM

theKeyStrategiestosigantificallyBoostPhpaPplicationPerformenCeare:1)UseOpCodeCachingLikeLikeLikeLikeLikeCacheToreDuceExecutiontime,2)優化AtabaseInteractionswithPreparedStateTementStatementStatementAndProperIndexing,3)配置

PHP依賴注入容器:快速啟動PHP依賴注入容器:快速啟動May 13, 2025 am 12:11 AM

aphpdepentioncontiveContainerIsatoolThatManagesClassDeptions,增強codemodocultion,可驗證性和Maintainability.itactsasaceCentralHubForeatingingIndections,因此reducingTightCightTightCoupOulplingIndeSingantInting。

PHP中的依賴注入與服務定位器PHP中的依賴注入與服務定位器May 13, 2025 am 12:10 AM

選擇DependencyInjection(DI)用於大型應用,ServiceLocator適合小型項目或原型。 1)DI通過構造函數注入依賴,提高代碼的測試性和模塊化。 2)ServiceLocator通過中心註冊獲取服務,方便但可能導致代碼耦合度增加。

PHP性能優化策略。PHP性能優化策略。May 13, 2025 am 12:06 AM

phpapplicationscanbeoptimizedForsPeedAndeffificeby:1)啟用cacheInphp.ini,2)使用preparedStatatementSwithPdoforDatabasequesies,3)3)替換loopswitharray_filtaray_filteraray_maparray_mapfordataprocrocessing,4)conformentnginxasaseproxy,5)

PHP電子郵件驗證:確保正確發送電子郵件PHP電子郵件驗證:確保正確發送電子郵件May 13, 2025 am 12:06 AM

phpemailvalidation invoLvesthreesteps:1)格式化進行regulareXpressecthemailFormat; 2)dnsvalidationtoshethedomainhasavalidmxrecord; 3)

See all articles

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

Video Face Swap

Video Face Swap

使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

這個專案正在遷移到osdn.net/projects/mingw的過程中,你可以繼續在那裡關注我們。 MinGW:GNU編譯器集合(GCC)的本機Windows移植版本,可自由分發的導入函式庫和用於建置本機Windows應用程式的頭檔;包括對MSVC執行時間的擴展,以支援C99功能。 MinGW的所有軟體都可以在64位元Windows平台上運作。

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser是一個安全的瀏覽器環境,安全地進行線上考試。該軟體將任何電腦變成一個安全的工作站。它控制對任何實用工具的訪問,並防止學生使用未經授權的資源。

DVWA

DVWA

Damn Vulnerable Web App (DVWA) 是一個PHP/MySQL的Web應用程序,非常容易受到攻擊。它的主要目標是成為安全專業人員在合法環境中測試自己的技能和工具的輔助工具,幫助Web開發人員更好地理解保護網路應用程式的過程,並幫助教師/學生在課堂環境中教授/學習Web應用程式安全性。 DVWA的目標是透過簡單直接的介面練習一些最常見的Web漏洞,難度各不相同。請注意,該軟體中

Dreamweaver Mac版

Dreamweaver Mac版

視覺化網頁開發工具

EditPlus 中文破解版

EditPlus 中文破解版

體積小,語法高亮,不支援程式碼提示功能