php應用mktime擷取時間戳記的例子分析

來源:互聯網
上載者:User
  1. $now = mktime(0,0,0,date("m"),date("d"),date("Y"));
  2. echo "now is ".date("Y/m/d", $now);
複製代碼

顯示結果: now is 2012/05/30 顯然這不是我想要的結果。 於是,按照舊有的思維,想當然的改造成下面這個形式:

  1. $now = mktime(date("h"),date("M"),date("s"),date("m"),date("d"),date("Y"));
  2. echo "now is ".date("Y/M/d h:i:s", $now);
複製代碼

注意紅色的部分,通常如果月份用m,那麼分鐘就應該是M。或者前者用M,後者用m。 顯示結果: Warning: mktime() expects parameter 2 to be long, string given in D:\usr\webroot\testPHP\index.php on line 46 now is 1970/01/01 08:Jan:00

正確答案是這樣的:

  1. $now = mktime(date("h"),date("i"),date("s"),date("m"),date("d"),date("Y"));
  2. echo "now is ".date("Y/m/d h:i:s", $now);
複製代碼

哈哈~是“i”而不是什麼m或者M,這裡給出大家這個樣本只是想讓PHP的初學少走一些彎路。 至於M是什麼意思,聰明的,你肯定明白的。顯示結果: now is 2012/05/30 04:54:25

>>> 您可能感興趣的文章:php中time(),date(),mktime()的區別詳解php中time()和mktime()用法的區別分析php中strtotime()與mktime() 的Y2K38漏洞 2038年問題

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.