0

我有以下代码

数据库中的日期格式是 (yyyy.mm.dd) 所以我想将它转换/格式化为 (dd.mm.yyyy)

此代码正在从数据库中读取日期

                    {
                      echo '<span class="badge badge-success" style="background-color:red;">Nicht Verf&uuml;gbar</span> <p><i class="fas fa-info-circle" aria-hidden="true" style="color:Red;"></i> Vergeben bis :<span style="color:red;font-weight:600;">';
                      echo htmlentities($result->VerfuegbarAb);
                      echo '</span></p>';
                    }

我的问题,我怎样才能把它放到我的代码中?我不知道如何在这段代码中添加时间格式,是的,这段代码看起来很糟糕,并且会是一个更好的解决方案,但我仍在学习 php,我将通过一切来变得更好:) 希望有人能提供帮助我会很棒的。提前致谢

4

2 回答 2

2

你可以做

$newLocale = setlocale(LC_TIME, 'de_DE', 'de_DE.UTF-8');
$formatted_date = strftime('%d. %B %Y',$result->VerfuegbarAb);

为此,需要在您的系统上安装语言环境“de_DE”。

PS:感谢您htmlentities()在从数据库中获取数据后作为初学者使用。这是一个很好的习惯,而且经常被遗忘。

于 2020-05-03T13:19:46.603 回答
1

这对我有用:

echo date( 'd.m.Y', strtotime('2020-05-03'));

或者:

$testdate = '2020.05.03';

echo date( 'd.m.Y', strtotime(str_replace('.','-',$testdate)));

在你的情况下:

echo date( 'd.m.Y', strtotime(str_replace('.','-',$result->VerfuegbarAb)));
于 2020-05-03T13:27:23.970 回答