我有一个PHP脚本,该脚本正在从数据库中返回值。特别是跟踪号和创建跟踪号的时间戳。
我试图弄清楚如何格式化此时间戳,下面的值是如何返回时间戳。
20180828115208
<div class="resul-count" align="center">
Found <?php echo $query->num_rows; ?> Results.
</div><br>
if($query->num_rows){
while($r = $query->fetch_object()){
?>
<div class="result">
<tr>
<td><?php echo $r->ShipToCompanyorName; ?></td>
<td><?php echo $r->ShipToAttention; ?></td>
<td><?php echo $r->ShipToAddress1; ?></td>
<td><?php echo $r->ShipToCityorTown; ?></td>
<td><?php echo $r->ShipToStateProvinceCounty; ?></td>
<td><?php echo $r->ShipToPostalCode; ?></td>
<td><?php echo $r->ShipmentInformationShipmentProcessTimestamp; ?></td>
<td><a href="http://wwwapps.ups.com/WebTracking/track?track=yes&trackNums=<?= $r->PackageTrackingNumber; ?>"><?= $r->PackageTrackingNumber;?></a></td>
答案 0 :(得分:2)
您可以使用DateTime::createFromFormat
$date = DateTime::createFromFormat('YmdHis', $r->ShipmentInformationShipmentProcessTimestamp);
echo $date->format('Y-m-d'); //output 2018-08-28 or choose whatever format you want