每天一个工作小技巧,不要问为什么要发这些简单的函数,问就是上班摸鱼。
1.判断时间在今天、昨天、前天、几天前几点
/**
* 判断时间在今天、昨天、前天、几天前几点
* @param $targetTime
* @return false|string
*/
function getTime($targetTime)
{
// 今天最大时间
$todayLast = strtotime(date('Y-m-d 23:59:59'));
$agoTimeTrue = time() - $targetTime;
$agoTime = $todayLast - $targetTime;
$agoDay = floor($agoTime / 86400);
if ($agoTimeTrue < 60) {
$result = '刚刚';
} elseif ($agoTimeTrue < 3600) {
$result = (ceil($agoTimeTrue / 60)) . '分钟前';
} elseif ($agoTimeTrue < 3600 * 12) {
$result = (ceil($agoTimeTrue / 3600)) . '小时前';
} elseif ($agoDay == 0) {
$result = '今天 ' . date('H:i', $targetTime);
} elseif ($agoDay == 1) {
$result = '昨天 ' . date('H:i', $targetTime);
} elseif ($agoDay == 2) {
$result = '前天 ' . date('H:i', $targetTime);
} elseif ($agoDay > 2 && $agoDay < 16) {
$result = $agoDay . '天前 ' . date('H:i', $targetTime);
} else {
$format = date('Y') != date('Y', $targetTime) ? "Y-m-d H:i" : "m-d H:i";
$result = date($format, $targetTime);
}
return $result;
}
2.mysql快速清空数据表
truncate table name;
3.因为大规模数据处理 内存占用得接触一定限制
ignore_user_abort(true);
ini_set('memory_limit', '512M');
ini_set('pcre.backtrack_limit', 100000000);