Created
January 6, 2016 08:15
-
-
Save flowerains/58177b583725b80fd10e to your computer and use it in GitHub Desktop.
判断时间戳来输出刚刚/分钟前/小时前/昨天/时间 time
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function T($time) { | |
//获取今天凌晨的时间戳 | |
$day = strtotime(date('Y-m-d',time())); | |
//获取昨天凌晨的时间戳 | |
$pday = strtotime(date('Y-m-d',strtotime('-1 day'))); | |
//获取现在的时间戳 | |
$nowtime = time(); | |
$tc = $nowtime-$time; | |
if($time<$pday){ | |
$str = date('Y-m-d H:i:s',$time); | |
}elseif($time<$day && $time>$pday){ | |
$str = "昨天"; | |
}elseif($tc>60*60){ | |
$str = floor($tc/(60*60))."小时前"; | |
}elseif($tc>60){ | |
$str = floor($tc/60)."分钟前"; | |
}else{ | |
$str = "刚刚"; | |
} | |
return $str; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment