PHP time() date() strtotime()日期函數總結

來源:互聯網
上載者:User

標籤:style   ar   for   strong   sp   檔案   div   2014   on   

日期函數總結——一、返回時間戳記——若整體數值超出電腦能力範圍,返回空。1. time();返回當前的 Unix 時間戳記 例:$a=time(); var_dump($a); //輸出:int(1392192781)2.strtotime();將其他格式解析為 Unix 時間戳記 例:$b = strtotime ( "now" ); var_dump($b); //輸出:int(1392192781) /*下括弧內格式例: ( "10 September 2000" ) ( "+1 day" )明天 ( "+1 days" )明天 ( "+1 week" ) ( "+1 week 2 days 4 hours 2 seconds" ) ( "next Thursday" )下周二 ( "last Monday" ) ( "2011-5-19 14:07" ); */3.mktime(時[,分[,秒[,月[,日[,年]]]]]); 都可以超出自然範圍,如27月,超出向高位加;若整體數值超出電腦能力範圍,返回false。 例:var_dump(mktime(12,0,0,12,30,2012)); //輸出:int(1356868800)4.microtime();返回微秒精度的時間戳記字串。 二、返回一個數組1.getdate();時間戳記(預設今天)返回一個數組。 $today = getdate(); var_dump($today); /*輸出數組: array(11) {  ["seconds"]=>int(32)    ["minutes"]=>int(27)    ["hours"]=>int(8)  ["mday"]=>int(12)  ["wday"]=>int(3)  ["mon"]=>int(2)  ["year"]=>int(2014)  ["yday"]=>int(42)  ["weekday"]=>string(9) "Wednesday"  ["month"]=>string(8) "February"  [0]=>int(1392193652) } */三、格式化輸出date();  格式string date ( string format [, int timestamp] )  string format 常用: Y:四位元年   m:月01-12   n:月1-12     d:天01-31  j:天1-31  H:時24時制   h:小時12制  i:分鐘00-59  s:秒00-59  w:星期幾0-6 A:上午AM或下午PM          a:上午am或下午pm。 例:var_dump(date("Y-m-d H:i:s",1391919385)); //string(19) "2014-02-09 04:16:25" 四、修改預設時區1、修php.ini設定檔: date.timezone = Etc/GMT+82、date_default_timezone_set(); 設定用於一個指令碼中所有日期時間函數的預設時區 。如:date_default_timezone_set("PRC"); //中國時區。另:date_default_timezone_get(); //擷取當前時區

 

 那麼問題來了:

1. 求今天淩晨的時間戳記?

2. 求明年1月1號距離今天(第二天淩晨算起)有多少天? 

 

PHP time() date() strtotime()日期函數總結

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.