/**
* 格式化聊天列表时间
* @param $timestamp int 时间戳
* @return false|string
*/
public static function formatchatlisttime($timestamp){
$today = strtotime('today');
$yesterday = strtotime('yesterday');
// 本周一
$thismonday = $today - ((date('w',time()) == 0 ? 7 : date('w',time()))-1)*24*3600;
// 上周一
$lastmonday = $thismonday - 7*24*3600;
if ($timestamp > $today){
$a = date('a', $timestamp);
$t = date('h:i', $timestamp);
if ($a == 'am'){
$a = '上午 ';
}else{
$a = '下午 ';
}
$result = $a.$t;
}else if ($timestamp > $yesterday){
$result = '昨天';
}else if ($timestamp > $thismonday){
$result = self::getweekdesc($timestamp);
}else if ($timestamp > $lastmonday){
$result = '上' . self::getweekdesc($timestamp);
}else{
if (date('y', $timestamp) == date('y', time())){
$result = self::datetimeformat($timestamp, 'm月d日');
}else{
$result = self::datetimeformat($timestamp, 'y年m月d日');
}
}
return $result;
}
/**
* 获取指定时间戳的星期几-中文描述
* @param int $timestamp 时间戳
* @return string
*/
public static function getweekdesc($timestamp){
if(intval($timestamp) == 0){
return '';
}
$week = date('w', $timestamp);
switch ($week){
case 0:
$desc = '星期日';
break;
case 1:
$desc = '星期一';
break;
case 2:
$desc = '星期二';
break;
case 3:
$desc = '星期三';
break;
case 4:
$desc = '星期四';
break;
case 5:
$desc = '星期五';
break;
case 6:
$desc = '星期六';
break;
default:
$desc = '';
break;
}
return $desc;
}