简体   繁体   English

如何将日期时间值显示为特定文本

[英]How do I display Date time value as Specific Text

I have dates stored in the following format: 2022-08-09 02:36:18我以以下格式存储日期: 2022-08-09 02:36:18

I would like to Display this information as: Aug 9th, 2022 2:36am我想将此信息显示为:2022 年 8 月 9 日凌晨 2:36

I have tried: $result = $date->format('M jS, Y');我试过: $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 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 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") .试试$result = date_format($date,"M jS, Y h:ia") Checking date_format() function is using date_format(object, format) as the correct syntax.检查date_format() function 使用date_format(object, format)作为正确的语法。

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));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM