如何以2018年2月23日格式显示日期时间'

时间:2018-02-23 10:54:17

标签: php date datetime

我是这样的字符串:2018-02-21 15:10:23。 我需要显示这样的日期' 23 Febbraio 2018'并且,我使用此代码将字符串转换为DateTime:

$post_date_to_DateTime = new DateTime($post_date_string);
$post_date = $post_date_to_DateTime->format('Y-m-d');

现在,我必须以格式文本和日期和年份提取月份来编写日期(用意大利语)。 有一个使用一些php日期函数的快速方法,或者我必须创建一个包含所有Months意大利语名称的数组,然后创建一个特定的字符串?

提前致谢!

4 个答案:

答案 0 :(得分:1)

试试这个(你的要求):

$post_date = date('j F Y', strtotime('2018-02-21 15:10:23'));

更多格式请检查PHP - 日期 http://php.net/manual/en/function.date.php

答案 1 :(得分:0)

根据https://secure.php.net/manual/en/function.date.php 您可以通过以下方式获取英文月份名称:

$post_date_to_DateTime->format('F');

要获得意大利语名称,您必须自己定义它们,就像您已经猜到的那样。

答案 2 :(得分:0)

使用strftime - 根据区域设置格式化本地时间/日期

echo strftime('%e %B %Y', strtotime('2018-02-21 15:10:23'));

%d一个月中的两位数日(带前导零)01到31

%e每月的某一天,前面有一位数字。 1至31

%B完整月份名称,基于1月到12月的区域设置

%Y年份的四位数表示示例:2038

了解更多信息Click Here

答案 3 :(得分:0)

 import { UICoreModule } from 'ui-core';

 @NgModule({
 imports:[
    UICoreModule
 ],
 providers:[
    //how to use the AuthService from UICoreModule 
 ]
 })
 export class HostModule { }

在此https://stackoverflow.com/a/1114547/5803974

之前阅读