我有三个包含日期、月份和年份的整数。我想将其转换为日期格式。
$date = 20;
$month = 8;
$year = 1989;
我已经应用了以下公式,但是当我回显 $mydate 时,它显示08-08-1990
$mydate = date("d-m-Y",mktime(0,0,0,$date,$month,$year));
我找不到我在哪里犯错了!
它会像
$mydate = date("d-m-Y",mktime(0,0,0,$month,$date,$year));
mktime()
会像对待他们一样
mktime(hours,minutes,seconds,month,day,year);
更改month
和day
位置反转
$mydate = date("d-m-Y",mktime(0,0,0,$month,$date,$year));
20-08-1989
mktime 语法 mktime(hour,minute,second,month,day,year)
改变它喜欢
$mydate = date("d-m-Y",mktime(0,0,0,$month,$date,$year));
mktime 语法是:mktime(hours,minutes,seconds,month,day,year);
mktime 会为你做的!
$date = date("d-m-Y",mktime(0,0,0,$month,$date,$year));
您可以使用 strtotime 函数。
例如
echo $a=strtotime("2009-03-18");
echo "<br />";
echo date("Y-m-d",$a);
这样做,它可以帮助你
$originalDate = $year."-".$month."-".$date;
$newDate = date("d-m-Y", strtotime($originalDate));
echo $newDate;