PHP時間戳格式彙總 獲取時間,時間戳

2022-03-31 12:17:50 字數 1753 閱讀 5819

1

php語言中的函式有許多種,各種應用方式不同,實現的功能也不盡相同。希望對新手的學習有所幫助!

25 一,php時間戳函式獲取指定日期的unix時間戳 strtotime(」2009-1-22″) 示例如下:67

echo

strtotime(」2009-1-22″) 結果:123255360089

說明:返回2023年1月22日0點0分0秒時間戳

1011

二,php時間戳函式獲取英文文字日期時間 示例如下:

1213

便於比較,使用date將當時間戳與指定時間戳轉換成系統時間

1415 (1)列印明天此時的時間戳strtotime(」+1day」)

16date(」y-m-d h:i:s」,time()) 結果:2009-01-22 09:40:25

18date(」y-m-d h:i:s」,strtotime(」+1 day」)) 結果:2009-01-23 09:40:25

2021 (2)列印昨天此時的時間戳strtotime(」-1day」)

22date(」y-m-d h:i:s」,time()) 結果:2009-01-22 09:40:25

24date(」y-m-d h:i:s」,strtotime(」-1 day」)) 結果:2009-01-21 09:40:25

2627 (3)列印下個星期此時的時間戳strtotime(」+1week」)

28date(」y-m-d h:i:s」,time()) 結果:2009-01-22 09:40:25

30date(」y-m-d h:i:s」,strtotime(」+1 week」)) 結果:2009-01-29 09:40:25

3233 (4)列印上個星期此時的時間戳strtotime(」-1week」)

34date(」y-m-d h:i:s」,time()) 結果:2009-01-22 09:40:25

36date(」y-m-d h:i:s」,strtotime(」-1 week」)) 結果:2009-01-15 09:40:25

3839 (5)列印指定下星期幾的時間戳strtotime(」next

thursday」)

40date(」y-m-d h:i:s」,time()) 結果:2009-01-22 09:40:25

42date(」y-m-d h:i:s」,strtotime(」next thursday」)) 結果:2009-01-29 00:00:00

4445 (6)列印指定上星期幾的時間戳strtotime(」last thursday」)

46date(」y-m-d h:i:s」,time()) 結果:2009-01-22 09:40:25

48date(」y-m-d h:i:s」,strtotime(」last thursday」)) 結果:2009-01-15 00:00:00

5051 (7)列印前一天零點的時間戳

52$ystd = strtotime('-1 day'); //

昨天這個時刻的時間戳

53$ystd = date("y-m-d", $ystd); //

昨天的日期d

5455

$ystd = strtotime($ystd." 00:00:00"); //

昨天凌晨24點整的時間戳

56 以上php時間戳函式示例可知,strtotime能將任何英文文字的日期時間描述解析為unix時間戳,我們結合mktime()或date()格式化日期時間獲取指定的時間戳,實現所需要的日期時間。

PHP時間戳格式全部彙總 獲取時間 時間戳

php語言中的函式有許多種,各種應用方式不同,實現的功能也不盡相同。希望對新手的學習有所幫助!一,php時間戳函式獲取指定日期的unix時間戳 strtotime 2009 1 22 示例如下 echo strtotime 2009 1 22 結果 1232553600 說明 返回2009年1月22...

C 獲取時間戳,時間戳與時間格式互轉

最近專案中用到獲取時間的功能,現在把用到的分享一下。1.時間戳轉為 00 00時區 日期格式 yyyy mm dd hh mm ss 時間戳轉為 00 00時區 日期格式 yyyy mm dd hh mm ss public static datetime getutcdatetime string...

php 時間轉換時間戳 PHP日期格式轉時間戳

php 提供了函式可以方便的將各種形式的日期轉換為時間戳,該類函式主要是 strtotime 將任何英文文字的日期時間描述解析為時間戳。mktime 從日期取得時間戳。strtotime strtotime 函式用於將英文文字字串表示的日期轉換為時間戳,為 date 的反函式,成功返回時間戳,否則返...