我正在开展一个项目,我决定两次之间的时间。时间格式为HH:MM AM / PM。你会如何将其转换为以小时和分钟为单位的经过时间?
以下是代码。
<?php
$flightcount = 0;
$pdo = Database::connect();
$pdo1 = Database::connect();
$sql = "SELECT * FROM FlightBasic ORDER BY STR_TO_DATE(DepartTime, '%l:%i %p')";
$sql2 = "SELECT * FROM Connections";
$Org = $_GET["origin"];
$Dest = $_GET["destination"];
$DDate = $_GET["ddate"];
$ADate = $_GET["adate"];
$sql2 = "SELECT * FROM connections";
foreach ($pdo->query($sql) as $row) {
if($row["Date"] == $DDate){
if($row["Date"] == $DDate){
foreach ($pdo1->query($sql2) as $row2) {
$conn = $row2["Connection"];
if($row2["Origin"]==$Org && $row2["Destination"]==$Dest){
if($row["Origin"]==$Org && $row["Destination"]==$conn){
$fldpt = $row["DepartTime"];
$flarr = $row["ArriveTime"];
$flnum = $row["FlightNumber"];
$sql3 = "";
echo
$fltr = $row2["TravelTime"];
foreach ($pdo->query($sql) as $row) {
if($row["Origin"]==$conn && $row["Destination"]==$Dest){
echo '<tr style="color:black; height:20px; background-color:#95AFB8">';
echo '<td align="center">' . $fldpt . '</td>';
echo '<td align="center" >' . $flarr . '</td>';
echo '<td align="center" >' . $flnum . '</td>';
echo '<td align="center" valign="middle" rowspan="2" width="108">1 Stop: <br> Stops In ' . $row2['Connection'] . '</td>';
echo '<td align="center" valign="center" rowspan="2">' . $fltr . '</td>';
echo '</tr>';
echo '<tr style="color:black; height:20px; background-color:#DFEBF0">';
echo '<td align="center" width="82">' . $row['DepartTime'] . '</td>';
echo '<td align="center" width="84">' . $row['ArriveTime'] . '</td>';
echo '<td align="center" width="94">' . $row['FlightNumber'] . '</td>';
echo '</tr>';
}
}
}
}
}
}
if($row["Origin"]==$Org && $row["Destination"]==$Dest){
echo '<tr style="color:black; height:40px; background-color:#95AFB8">';
echo '<td align="center">' . $row['DepartTime'] . '</td>';
echo '<td align="center">' . $row['ArriveTime'] . '</td>';
echo '<td align="center">' . $row['FlightNumber'] . '</td>';
echo '<td align="center">Nonstop</td>';
echo '<td align="center">' . $row['TravelTime'] . '</td>';
echo '</tr>';
}
}
}
Database::disconnect();
?>
感谢您的帮助!
答案 0 :(得分:0)
这是一个计算时间差异的简单代码。你的代码没有明确你真正想要的东西,因此,根据你的需要改变它。
<?php
$first = new DateTime( Your time );
$second = new DateTime( Another time );
$diff = $first->diff( $second );
这打印的内容如下:2005年8月8日星期一03:12:46
echo date('l jS \of F Y h:i:s A');
echo $diff->format( '%H:%I:%S' ); // -> Difference
?>
A(或a)显示AM / PM格式。 PHP文档http://php.net/manual/en/function.date.php
中的更多详细信息