亚洲最大看欧美片,亚洲图揄拍自拍另类图片,欧美精品v国产精品v呦,日本在线精品视频免费

  • 站長資訊網(wǎng)
    最全最豐富的資訊網(wǎng)站

    php怎么算兩個時間中差幾天

    方法:1、利用strtotime()函數(shù)將兩個指定的時間格式化為時間戳,語法為“strtotime(指定時間)”;2、將兩個時間戳相減,獲取兩個時間秒數(shù)的時間差;3、將秒數(shù)的時間差轉換為天數(shù)的時間差即可,語法為“秒數(shù)的時間差/86400”。

    php怎么算兩個時間中差幾天

    本文操作環(huán)境:Windows10系統(tǒng)、PHP7.1版、Dell G3電腦

    php怎么算兩個時間中差幾天

    1、利用strtotime函數(shù)將時間格式化為時間戳

    strtotime() 函數(shù)將任何英文文本的日期或時間描述解析為 Unix 時間戳(自 January 1 1970 00:00:00 GMT 起的秒數(shù))。

    語法為:

    strtotime('年-月-日 時:分:秒')

    示例如下:

    <?php  echo(strtotime('2022-04-13 12:25:00'));  ?>

    輸出結果:

    php怎么算兩個時間中差幾天

    2、將兩個時間戳相減,獲取兩個時間的時間差

    3、將獲取的時間差除以86400就是兩個時間相差的天數(shù)

    示例如下:

    <?php  $time1=strtotime('2022-04-13 12:25:00');  $time2=strtotime('2022-04-15 12:25:00');  $diff_seconds = $time2 - $time1; $diff_days = $diff_seconds/86400; echo($diff_days . "天"); ?>

    輸出結果:

    php怎么算兩個時間中差幾天

    推薦學習:《PHP視頻教程》

    贊(0)
    分享到: 更多 (0)
    網(wǎng)站地圖   滬ICP備18035694號-2    滬公網(wǎng)安備31011702889846號