我在两个日期时间之间得到无效的间隔
$date = new \DateTime();
$zurich = new DateTimeZone('Asia/Kolkata');
$datetimeFormat = 'Y-m-d H:i:s';
$date->setTimestamp($request->travel_time);
$d1 = $date->format($datetimeFormat);
$date2 = new \DateTime();
$d2 = $alreadyCreatedRoute[0]->travel_time;
$datetime1 = new DateTime($d2,$zurich);
$datetime2 = new DateTime($d1,$zurich);
$interval = $datetime1->diff($datetime2);
`echo $diff_in_minutes = $interval->format('%h')." Hours ".$interval->format('%i')." Minutes";`
**DateTime Object([date] => 2018-02-12 10:19:11.000000 [timezone_type] =>3
[timezone] => Asia/Kolkata**
)
**DateTime Object([date] => 2018-02-12 00:11:00.000000 [timezone_type] =>3
[timezone] => Asia/Kolkata)**
答案 0 :(得分:0)
我不确定你到底想要什么但是如果它的日期差异那么这里是找到2 DateTime之间差异的代码
class Insurance
{
private int customers;
public Insurance(string agent, int customers)
{
Agent = Agent;
Customers = Customers;
}
public string Agent { get; set; }
public int Customers
{
get { return customers; }
set { customers = Math.Max(value, 0); }
}
}