【问题标题】:Formatting Date in PHP when value is returned as a string当值作为字符串返回时,在 PHP 中格式化日期
【发布时间】:2019-02-26 07:09:22
【问题描述】:

我有一个从数据库返回值的 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>

【问题讨论】:

标签: php mysql mysqli timestamp


【解决方案1】:

您可以使用DateTime::createFromFormat

$date = DateTime::createFromFormat('YmdHis', $r->ShipmentInformationShipmentProcessTimestamp);
echo $date->format('Y-m-d'); //output 2018-08-28 or choose whatever format you want

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-04-08
    • 2014-05-30
    • 2016-06-25
    • 2023-04-07
    • 2015-06-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多