日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程语言 > php >内容正文

php

php日期时间代码,PHP日期计算

發(fā)布時(shí)間:2023/12/20 php 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 php日期时间代码,PHP日期计算 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

為了顯示一個(gè)事件的持續(xù)時(shí)間,我試圖計(jì)算兩個(gè)日期之間的差異。如果事件的持續(xù)時(shí)間為星期五17:00至星期日15:00,則針對(duì)該問題給出的大多數(shù)函數(shù)都將失敗。我的目標(biāo)是找出日期之間的區(qū)別,比如:

date('Ymd',$end)-date('Tmd',$begining);

但這很可能會(huì)失敗,因?yàn)橐荒隂]有99個(gè)月,一個(gè)月沒有99天。我可以將日期字符串轉(zhuǎn)換為unix時(shí)間戳,然后除以60*60*12,但有些日子的小時(shí)數(shù)要么大要么小,有時(shí)會(huì)有一個(gè)閏秒。所以我使用getDate()創(chuàng)建了自己的函數(shù),它返回一個(gè)關(guān)于時(shí)間戳的innformation數(shù)組。

/*

* datediff($first,$last)

* $first - unix timestamp or string aksepted by strtotime()

* $last - unix timestamp or string aksepted by strtotime()

*

* return - the difference in days betveen the two dates

*/

function datediff($first,$last){

$first = is_numeric($first) ? $first : strtotime($first);

$last = is_numeric($last ) ? $last : strtotime($last );

if ($last

// Can't calculate negative difference in dates

return -1;

}

$first = getdate($first);

$last = getdate($last );

// find the difference in days since the start of the year

$datediff = $last['yday'] - $first['yday'];

// if the years do not match add the appropriate number of days.

$yearCountedFrom = $first['year'];

while($last['year'] != $yearCountedFrom ){

// Take leap years into account

if( $yearCountedFrom % 4 == 0 && $yearCountedFrom != 1900 && $yearCountedFrom != 2100 ){

//leap year

$datediff += 366;

}else{

$datediff += 365;

}

$yearCountedFrom++;

}

return $datediff;

}

關(guān)于gregoriantojd()函數(shù),它可能會(huì)工作,但是我有點(diǎn)不安,因?yàn)槲也焕斫馑侨绾喂ぷ鞯摹?/p> 創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎(jiǎng)勵(lì)來咯,堅(jiān)持創(chuàng)作打卡瓜分現(xiàn)金大獎(jiǎng)

總結(jié)

以上是生活随笔為你收集整理的php日期时间代码,PHP日期计算的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。