php 转换为日期格式 dd/mm/yyyy
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2671145/
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
Convert to date format dd/mm/yyyy
提问by Rui Gon?alves
I have the following date: 2010-04-19 18:31:27. I would like to convert this date to the dd/mm/yyyyformat.
我有以下日期:2010-04-19 18:31:27。我想将此日期转换为dd/mm/yyyy格式。
回答by Michael Mrozek
You can use a regular expression or some manual string fiddling, but I think I prefer:
您可以使用正则表达式或一些手动字符串摆弄,但我想我更喜欢:
date("d/m/Y", strtotime($str));
回答by Murali Krishna kilari
<?php
$test1='2010-04-19 18:31:27';
echo date('d/m/Y',strtotime($test1));
?>
try this
尝试这个
回答by Henry Hammond
If your date is in the format of a string use the explode function
如果您的日期是字符串格式,请使用爆炸函数
array explode ( string $delimiter , string $string [, int $limit ] )
//In the case of your code
$length = strrpos($oldDate," ");
$newDate = explode( "-" , substr($oldDate,$length));
$output = $newDate[2]."/".$newDate[1]."/".$newDate[0];
Hope the above works now
希望以上工作现在
回答by SeanJA
There is also the DateTimeobject if you want to go that way: http://www.php.net/manual/en/datetime.construct.php
DateTime如果你想这样做,也有对象:http: //www.php.net/manual/en/datetime.construct.php
回答by user3045510
Try this:
尝试这个:
$old_date = Date_create("2010-04-19 18:31:27");
$new_date = Date_format($old_date, "d/m/Y");
回答by Devang Patel
$source = 'your varible name';
$date = new DateTime($source);
$_REQUEST["date"] = $date->format('d-m-Y');
echo $_REQUEST["date"];

