我正在为一家公司开发一个旅游门户网站,但很难找到时差。
在am / pm的日期时间格式中使用相同的存储日期,我必须...
是的,还有一件事;由于旅游公司在印度运营并遵循12小时时间格式,因此我很难计算时差。
答案 0 :(得分:0)
请使用如下的date_diff函数,它也允许am / pm。
print_r( date_diff( date_create('2015-10-04 01:00:00am'), date_create('2015-10-04 02:00:00pm')) );
输出 - >
DateInterval Object
(
[y] => 0 // corresponds to years
[m] => 0 // corresponds to months
[d] => 0 // corresponds to days
[h] => 13 // corresponds to hours
[i] => 0 // corresponds to minutes
[s] => 0 // corresponds to seconds
[weekday] => 0
[weekday_behavior] => 0
[first_last_day_of] => 0
[invert] => 0
[days] => 0
[special_type] => 0
[special_amount] => 0
[have_weekday_relative] => 0
[have_special_relative] => 0
)
从DateInterval对象中,您可以获得时差。
$datetime_diff_Obj = date_diff( date_create('2015-10-04 01:00:00am'), date_create('2015-10-04 02:00:00pm'));
echo $datetime_diff_Obj->h; // hours
echo $datetime_diff_Obj->i ;// minutes
echo $datetime_diff_Obj->s; // seconds
要获得数小时的差异,请使用以下代码
$time_diff = (round ( abs ( strtotime('2015-10-04 01:00:00am') - strtotime('2015-10-02 02:00:00pm') ) /3600 ) );
echo $time_diff." hrs ";
输出 - >
35 hrs