PHP 日期格式到月份名称和年份
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18635051/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
PHP Date Format to Month Name and Year
提问by user2750491
I have this date data :
我有这个日期数据:
20130814
20130814
How to get string output like this : (in PHP)
如何获得这样的字符串输出:(在 PHP 中)
"August 2013"
“2013年8月”
回答by Fluffeh
You could use:
你可以使用:
echo date('F Y', strtotime('20130814'));
which should do the trick.
这应该可以解决问题。
Edit: You have a date which is in a string format. To be able to format it nicelt, you first need to change it into a date itself - which is where strtotime comes in. It is a fantastic feature that converts almost any plausible expression of a date into a date itself. Then we can actually use the date() function to format the output into what you want.
编辑:您有一个字符串格式的日期。为了能够将其格式化为 nicelt,您首先需要将其更改为日期本身 - 这就是 strtotime 的用武之地。它是一个很棒的功能,可以将日期的几乎所有合理表达方式转换为日期本身。然后我们实际上可以使用 date() 函数将输出格式化为您想要的格式。
回答by Mawia HL
I think your date data should look like 2013-08-14.
我认为您的日期数据应该类似于 2013-08-14。
<?php
$yrdata= strtotime('2013-08-14');
echo date('M-Y', $yrdata);
?>
// Output is Aug-2013
回答by Rakesh Sharma
if you want same string output then try below else use without double quotes for proper output
如果您想要相同的字符串输出,请尝试在下面使用其他不带双引号的正确输出
$str = '20130814';
echo date('"F Y"', strtotime($str));
//output : "August 2013"