PHP時間戳記比較

來源:互聯網
上載者:User

標籤:php 時間戳記

有時候,要比較兩個時間之間相差的天數

可以採用strtortime()函數,該函數預期接受一個包含英文日期格式的

字串,並嘗試將其解析為UNIX時間戳記

int strtotime(string time [,int now]);

strtotime()函數有兩個參數。如果參數time的格式是絕對時間,

則now參數不起作用,如果參數time的格式是相對時間,其對應的

時間由參數now來提供。

<?php

$a=strtotime("now");       //擷取目前時間的時間戳記-秒數

$b=strtotime("05 May 2010");  //擷取指定時間的時間戳記-秒數

echo $a."\n";  //輸出擷取的時間戳記

echo "輸出日期".date("Y-m-d H:i:s",$a)."<br/><br/>";  //格式化輸出時間戳記

echo $b."\n"; //輸出指定時間的時間戳記

echo "輸出日期".date("Y-m-d H:i:s",$b)."<br><br/>"; //格式化輸出指定時間時間戳記

$c=ceil(($a-$b)/(3600*24)); //返回一個整數

echo "距2010年5月5日已過去".$c."天";

?>


注意,在unxi系統中,日期與時間表示自1970年1月1日零點起到,到當前時刻的秒數,這種

時間成為UNIX時間戳記

---------------------------------分割線-----------------------------------------

650) this.width=650;" src="http://s3.51cto.com/wyfs02/M00/59/58/wKioL1TQj96zSH4FAACgA6df4xY007.jpg" title="QQ20150203092742.png" alt="wKioL1TQj96zSH4FAACgA6df4xY007.jpg" />




END!


本文出自 “百折不回” 部落格,請務必保留此出處http://changbo.blog.51cto.com/1316452/1611193

PHP時間戳記比較

聯繫我們

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