[英]How do I display Date time value as Specific Text
我以以下格式存储日期: 2022-08-09 02:36:18
我想将此信息显示为:2022 年 8 月 9 日凌晨 2:36
我试过: $result = $date->format('M jS, Y');
有了这个但没有奏效。
尝试这种格式会导致我的日期从页面上消失。 我在这里想念什么?
CSS
.posttime {
height: auto;
width: auto;
margin: 0px 0px 0px 0px;
font-size: 15px;
font-weight: normal;
font-family: Arial Narrow Bold;
position: absolute;
top: 20px;
right: 20px;
}
PHP
echo '
<Div class="postBox">
<img class="postprofilepicture" src="../profilepictures/'.$ProfilePicture.'">
<p class="postusername">'.$UserName.'<p>
<p class="posttime">'.date_format($Date,"M jS, Y h:i A").'<p>
<p>'.$Text.'<p>
</div>
<br>
';
试试$result = date_format($date,"M jS, Y h:ia")
。 检查date_format()
function 使用date_format(object, format)
作为正确的语法。
或者你使用'
而不是"
。这行得通吗?
请参阅此链接。
你可以试试这个-
<?php
$date=date_create("2022-08-09 02:36:18");
echo date_format($date,"M jS, Y h:i A"); // Aug 9th, 2022 02:36 AM
?>
这样做很简单:
$date = "2022-08-09 02:36:18";
echo date('M jS,Y h:i A',strtotime($date));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.