我有以下日期:2010-04-19 18:31:27。我想将此日期转换为dd/mm/yyyy格式。
你可以使用正则表达式或一些手动的字符串操作,但我认为我更喜欢:
date("d/m/Y", strtotime($str));
<?php
$test1='2010-04-19 18:31:27';
echo date('d/m/Y',strtotime($test1));
?>
试一下
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];
简单尝试一下 $date=date('d/m/Y',strtotime($yourdatevariable))
或者你想转换为 d-m-Y 只需简单地 编辑上面的 d/m/Y 为 d-m-Y
试试这个:
$old_date = Date_create("2010-04-19 18:31:27");
$new_date = Date_format($old_date, "d/m/Y");
$source = 'your varible name';
$date = new DateTime($source);
$_REQUEST["date"] = $date->format('d-m-Y');
echo $_REQUEST["date"];
strtotime(“2010-04-19 18:31:27”);
返回自时代以来的秒数,1271716287
(对于我的TZ)。date()
采用格式字符串和时代int;格式字符串告诉它要返回什么,“d / m / Y”是天数为零填充的int,月份为零填充的int,年份为四位数。由于格式字符串中未包含时间参数(例如“d / m / Y h:i:s”),因此它们不会被返回。 - Michael Mrozekdate("d/m/Y");
。 - Junior Mayhé