我试图将日期从yyyy-mm-dd转换为dd-mm-yyyy(但不是SQL);然而,我不知道日期函数如何需要时间戳,我无法从这个字符串中获得时间戳。
这怎么可能呢?
我试图将日期从yyyy-mm-dd转换为dd-mm-yyyy(但不是SQL);然而,我不知道日期函数如何需要时间戳,我无法从这个字符串中获得时间戳。
这怎么可能呢?
当前回答
下面给出的PHP代码使用mktime()生成明天的日期,并将其格式更改为dd/mm/yyyy格式,然后使用echo打印它。
$tomorrow = mktime(0, 0, 0, date("m"), date("d") + 1, date("Y"));
echo date("d", $tomorrow) . "/" . date("m", $tomorrow). "/" . date("Y", $tomorrow);
其他回答
有两种实现方法:
1.
$date = strtotime(date);
$new_date = date('d-m-Y', $date);
2.
$cls_date = new DateTime($date);
echo $cls_date->format('d-m-Y');
Use:
implode('-', array_reverse(explode('-', $date)));
如果没有日期转换开销,我不确定它会有多大影响。
您可以尝试strftime()函数。简单示例:strftime($time, '%d %m %Y');
date('m/d/Y h:i:s a',strtotime($val['EventDateTime']));
$newDate = preg_replace("/(\d+)\D+(\d+)\D+(\d+)/","$3-$2-$1",$originalDate);
此代码适用于所有日期格式。
由于您的旧日期格式,您可以更改替换变量的顺序,例如$3-$1-$2。