我有 Y-m-d H:i:s
格式的日期数组,例如:
array(5) {
[0]=> string(19) "2012-06-11 08:30:49"
[1]=> string(19) "2012-06-07 08:03:54"
[2]=> string(19) "2012-05-26 23:04:04"
[3]=> string(19) "2012-05-27 08:30:00"
[4]=> string(19) "2012-06-08 08:30:55"
}
我想知道最近的日期。
换句话说,今天是 2012 年 6 月 13 日,哪个日期时间最接近今天的日期?
从我的示例数组中,我期待 2012-06-11 08:30:49
。
我该怎么做?
最佳答案
使用 max()
, array_map()
, 和 strtotime()
.
$max = max(array_map('strtotime', $arr));
echo date('Y-m-j H:i:s', $max); // 2012-06-11 08:30:49
关于php - 从 "Y-m-d H:i:s"格式的日期数组中获取最近的日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11012891/