我正在尝试显示我通过$_GET
发送的日期,我的url格式是例如http://127.0.0.1/index.php?date=01/08/2018
。
结果是08-01-2018
,它改变了日期和月份的顺序,为什么?
$orginal_date= $_GET['date'];
$date = date("d-m-Y", strtotime($original_date));
echo $date;
发布于 2018-08-18 19:22:53
list($month, $day, $year) = explode("/", $_GET["date"]);
$date = sprintf("%d-%02d-%02d", $year, $month, $day);
发布于 2018-08-18 19:52:11
这看起来像是在假设php将如何使用strtotime并将其转换为时间戳。默认认为2018年1月8日是2018年1月8日。有一个date_create_from_format方法,你可以告诉它你想要的格式,然后你可以把它格式化成你想要的样子。
$orig = $_GET['date']; $date = date_create_from_format('d/m/Y', $orig); echo date_format($date, 'd-m-Y');
//result is 01-08-2018
发布于 2018-08-18 19:59:18
尝尝这个
list($month, $day, $year) = explode("/", $_GET["date"]);
echo date('d-m-Y',mktime(0, 0, 0, $month,$day, $year));
https://stackoverflow.com/questions/51908049
复制相似问题