php 显示日期格式
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5074531/
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
display date format
提问by Lucky13
I want to display 2-March-2011 is like '02-March-2011'.
我想显示 2-March-2011 就像 '02-March-2011'。
回答by Yoko Zunna
<?php
// Assuming today is March 10th, 2001, 5:16:18 pm, and that we are in the
// Mountain Standard Time (MST) Time Zone
$today = date("j-F-Y"); // 10-March-2001
$today = date("F j, Y, g:i a"); // March 10, 2001, 5:16 pm
$today = date("m.d.y"); // 03.10.01
$today = date("j, n, Y"); // 10, 3, 2001
$today = date("Ymd"); // 20010310
$today = date('h-i-s, j-m-y, it is w Day'); // 05-16-18, 10-03-01, 1631 1618 6 Satpm01
$today = date('\i\t \i\s \t\h\e jS \d\a\y.'); // it is the 10th day.
$today = date("D M j G:i:s T Y"); // Sat Mar 10 17:16:18 MST 2001
$today = date('H:m:s \m \i\s\ \m\o\n\t\h'); // 17:03:18 m is month
$today = date("H:i:s"); // 17:16:18
?>
Refer this link also....
也参考这个链接....
回答by JohnP
Just replace the hardcoded date with your value
只需用您的值替换硬编码日期
$timestamp = strtotime('2-March-2011');
$newDate = date('d-F-Y', $timestamp);
echo $newDate; //outputs 02-March-2011
回答by alex
回答by Patrick Fisher
Convert the input string to a timestamp, then format that as desired. See http://php.net/manual/en/function.date.phpfor formatting options.
将输入字符串转换为时间戳,然后根据需要对其进行格式化。有关格式选项,请参阅http://php.net/manual/en/function.date.php。
$input = '2-March-2011';
$time = strtotime($input);
$output = date('d-F-Y',$time);
Short version:
精简版:
echo date('d-F-Y',strtotime('2-March-2011'));
回答by My Other Me
A quick hop over to the documentationreveals that everyone else was correct when they said this:
快速跳转到文档会发现其他人说这句话时都是正确的:
echo date('d-F-Y', strtotime('2-March-2011'));
回答by Hassan
Code Sample : echo date('d-F-Y',strtotime('2011-03-02'));
代码示例:echo date('dF-Y',strtotime('2011-03-02'));
you can format you date in many ways here you can find all the formats date format
你可以用多种方式格式化你的日期在这里你可以找到所有的格式日期格式
回答by Adam
If you have the date as a Unix timestamp (eg: $date = time();
), then you can just use the inbuilt date()
function:
如果您将日期作为 Unix 时间戳(例如$date = time();
:),那么您可以使用内置date()
函数:
echo date('j-F-Y');
Otherwise, you can look at using strtotime()
(http://www.php.net/manual/en/function.strtotime.php) to get it into Unix time, or alternatively use a more object-oriented approach as alexhas shown.
否则,您可以考虑使用strtotime()
( http://www.php.net/manual/en/function.strtotime.php) 使其进入 Unix 时间,或者使用更面向对象的方法,如亚历克斯所示。