I have dates stored in the following format: 2022-08-09 02:36:18
I would like to Display this information as: Aug 9th, 2022 2:36am
I have tried: $result = $date->format('M jS, Y');
with this but not worked.
Trying this format causes my date to disappear from the page. What am I missing here?
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>
';
Try $result = date_format($date,"M jS, Y h:ia")
. Checking date_format()
function is using date_format(object, format)
as the correct syntax.
Either that or youre using '
instead of "
. Does this work?
Refer to this link .
You can try with this-
<?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
?>
Simple do by this:
$date = "2022-08-09 02:36:18";
echo date('M jS,Y h:i A',strtotime($date));
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.