在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
/** * 获得几天前,几小时前,几月前 * @param int $time 时间戳 * @param array $unit 时间单位 * @return bool|string */ function date_before($time, $unit = null) { $time = intval($time); $unit = is_null($unit) ? array("年", "月", "星期", "天", "小时", "分钟", "秒") : $unit; switch (true) { case $time < (NOW - 31536000) : return floor((NOW - $time) / 31536000) . $unit[0] . '前'; case $time < (NOW - 2592000) : return floor((NOW - $time) / 2592000) . $unit[1] . '前'; case $time < (NOW - 604800) : return floor((NOW - $time) / 604800) . $unit[2] . '前'; case $time < (NOW - 86400) : return floor((NOW - $time) / 86400) . $unit[3] . '前'; case $time < (NOW - 3600) : return floor((NOW - $time) / 3600) . $unit[4] . '前'; case $time < (NOW - 60) : return floor((NOW - $time) / 60) . $unit[5] . '前'; default : return floor(NOW - $time) . $unit[6] . '前'; } }
|
2022-08-30
2022-08-17
2022-11-06
2022-08-17
2022-07-18
请发表评论