PHP 将 ISO 日期转换为更易读的格式?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3106652/
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 Convert ISO date to more readable format?
提问by Dylan Taylor
Just a simple question. How do I convert a PHP ISO time (like 2010-06-23T20:47:48-04:00) to something more readable? Is there a function already built in PHP? I've looked around but I haven't seen anything to convert times. If there's not a function, is it possible?
只是一个简单的问题。如何将 PHP ISO 时间(如 2010-06-23T20:47:48-04:00)转换为更具可读性的内容?PHP中是否已经内置了一个函数?我环顾四周,但没有看到任何可以转换时间的东西。如果没有函数,有可能吗?
Thank you
谢谢
回答by zebediah49
$format = "d M Y"; //or something else that date() accepts as a format
date_format(date_create($time), $format);
回答by Mladen Janjetovic
Try this:
尝试这个:
echo date( "Y-m-d H:i:s", strtotime("2010-06-23T20:47:48-04:00") );
Format this part "Y-m-d H:i:s" using formatfrom this documentation http://php.net/manual/en/function.date.php
使用format本文档http://php.net/manual/en/function.date.php格式化此部分“Ymd H:i:s”
回答by Jeffrey Blake
Sounds like you're looking for the date function: http://php.net/function.date
听起来你正在寻找日期函数:http: //php.net/function.date
Possibly paired with the strtotime function: http://php.net/function.strtotime
可能与 strtotime 函数配对:http: //php.net/function.strtotime
回答by Void
回答by kiamlaluno
strptime()converts a string containing a time/date with the format passed as second argument to the function. The return value is an array containing values for day, month, year, hour, minutes, and seconds; you can use those values to obtain a string representing the date in the format you like.
strptime()将包含时间/日期的字符串转换为作为第二个参数传递给函数的格式。返回值是一个包含日、月、年、小时、分钟和秒值的数组;您可以使用这些值以您喜欢的格式获取表示日期的字符串。
strptime()is available since PHP 5.1.0, while the class DateTimeis available since PHP 5.2.0.
strptime()自 PHP 5.1.0 起可用,而DateTime类自 PHP 5.2.0 起可用。
回答by Raquibul Islam
echo strftime("%b %e %Y at %l:%M %p", strtotime($ios));
will do
会做
回答by user8981779
For a short date try this:
对于短期约会,请尝试以下操作:
$a_date = '2010-06-23T20:47:48-04:00';
echo date('Y-m-d', strtotime($a_date));

