类似新浪微博发布时间显示方式 比如 **分钟前 ** 小时前 昨天12:30 前天13:30等
来源:互联网 发布:catia软件培训 编辑:程序博客网 时间:2024/05/01 15:06
public static String getDayTime(String daytime){ //daytime 格式为yyyy-MM-dd HH:mm:ss
int mimutes = 0;
int days = 0;
int hours = 0;
String timeStr = "";
Date nowdate = new Date();
Date createdate = null;
if (daytime != null && !"".equals(daytime) && daytime.length()==19) {
try {
String pattern = "yyyy-MM-dd HH:mm:ss";
SimpleDateFormat format = new SimpleDateFormat(pattern);
createdate = format.parse(daytime);
} catch (ParseException e) {
e.printStackTrace();
}
if (nowdate.getDate()==createdate.getDate() && nowdate.getMonth() == createdate.getMonth() && nowdate.getYear() == createdate.getYear()) {
mimutes = TimeUtility.getMinutesDiff(nowdate,createdate);
if (mimutes == 0) {
timeStr = "刚刚";
}else if (mimutes > 0) {
if (mimutes > 0 && mimutes < 60) {
timeStr = String.valueOf(mimutes) + "分钟前";
}else{
hours = mimutes/24;
if (hours > 0 && hours <= 24) {
timeStr = String.valueOf(hours) + "小时前";
}
}
}
}else{
//int daysDiff = getDaysDiff(nowdate,createdate);
if (nowdate.getMonth() == createdate.getMonth()) {
days = nowdate.getDate() - createdate.getDate();
}else{
days = nowdate.getDate()+getDaysOfMonth(createdate) - createdate.getDate();
}
if (days == 1 ) {
timeStr = "昨天" + daytime.substring(10,16);
}else if (days == 2 ) {
timeStr = "前天" + daytime.substring(10,16);
}else{
timeStr = daytime.substring(0,16);
}
}
}
return timeStr;
}
/**
* 获取指定日期的月份总共有多少天
* @param date
* @return
*/
public static int getDaysOfMonth(Date date){
Calendar aCalendar = Calendar.getInstance();
aCalendar.setTime(date);
aCalendar.add(Calendar.MONTH, 1);
aCalendar.add(Calendar.DAY_OF_MONTH, -1);
date = aCalendar.getTime();
return date.getDate();
}
int mimutes = 0;
int days = 0;
int hours = 0;
String timeStr = "";
Date nowdate = new Date();
Date createdate = null;
if (daytime != null && !"".equals(daytime) && daytime.length()==19) {
try {
String pattern = "yyyy-MM-dd HH:mm:ss";
SimpleDateFormat format = new SimpleDateFormat(pattern);
createdate = format.parse(daytime);
} catch (ParseException e) {
e.printStackTrace();
}
if (nowdate.getDate()==createdate.getDate() && nowdate.getMonth() == createdate.getMonth() && nowdate.getYear() == createdate.getYear()) {
mimutes = TimeUtility.getMinutesDiff(nowdate,createdate);
if (mimutes == 0) {
timeStr = "刚刚";
}else if (mimutes > 0) {
if (mimutes > 0 && mimutes < 60) {
timeStr = String.valueOf(mimutes) + "分钟前";
}else{
hours = mimutes/24;
if (hours > 0 && hours <= 24) {
timeStr = String.valueOf(hours) + "小时前";
}
}
}
}else{
//int daysDiff = getDaysDiff(nowdate,createdate);
if (nowdate.getMonth() == createdate.getMonth()) {
days = nowdate.getDate() - createdate.getDate();
}else{
days = nowdate.getDate()+getDaysOfMonth(createdate) - createdate.getDate();
}
if (days == 1 ) {
timeStr = "昨天" + daytime.substring(10,16);
}else if (days == 2 ) {
timeStr = "前天" + daytime.substring(10,16);
}else{
timeStr = daytime.substring(0,16);
}
}
}
return timeStr;
}
/**
* 获取指定日期的月份总共有多少天
* @param date
* @return
*/
public static int getDaysOfMonth(Date date){
Calendar aCalendar = Calendar.getInstance();
aCalendar.setTime(date);
aCalendar.add(Calendar.MONTH, 1);
aCalendar.add(Calendar.DAY_OF_MONTH, -1);
date = aCalendar.getTime();
return date.getDate();
}
- 类似新浪微博发布时间显示方式 比如 **分钟前 ** 小时前 昨天12:30 前天13:30等
- 类似新浪微博发布时间显示方式 比如 **分钟前 ** 小时前 昨天12:30 前天13:30等
- 类似新浪微博动态发布时间转换机制,显示刚刚、几分钟前、几小时前、昨天、前天····
- 对时间进行格式化,例如刚刚、几秒前、几分钟前、几小时前、昨天、前天
- 用php判断时间戳来输出刚刚,分钟前,小时前昨天和时间
- php中时间轴开发,即显示为“刚刚”、“5分钟前”、“昨天10:23”等
- PHP CodeBase: 将时间显示为“刚刚”“n分钟/小时前”等
- NSDate类目-实现 1分钟前 X小时前 昨天的显示
- 根据刚刚,1分钟前,1小时前,几天前显示文章发布日期
- 根据刚刚,1分钟前,1小时前,几天前显示文章发布日期
- PHP时间转换今天昨天前天几天前
- java 时间戳 转 昨天前天 几小时前 刚刚
- PHP人性化时间显示,实现多少秒前,多少分钟前,多少小时前
- PHP人性化时间显示,实现多少秒前,多少分钟前,多少小时前
- JavaScript 对传入时间戳进行转换(1分钟内显示刚刚,1小时内显示xx分钟前,今日的显示时分,昨天显示昨天+时分,一年内显示月日时分,一年外显示年月日)
- 将时间戳转换为时间,并输出“刚刚”、“昨天”、“XX小时前”等
- php中时间轴开发,即显示为“刚刚”、“5分钟前”、“昨天
- php中时间轴开发,即显示为“刚刚”、“5分钟前”、“昨天10:23
- ubuntu安装verilog
- 浅析远程过程调用 RPC
- NSNotificationCenter 的详细说明
- excel 导入 完整例子
- rtl8192cu无线网卡移植时遇到issue nulldata to keep alive issue nulldata:0问题解决办法
- 类似新浪微博发布时间显示方式 比如 **分钟前 ** 小时前 昨天12:30 前天13:30等
- #小练习 SGMLParser 解析 HTML
- UML用例建模解析(一)
- java程序:在排序好的数组中添加一个数字,将添加后的数字插入到数组合适的位置。怎么写啊?
- CAN 波特率设置
- 关于gcc 1.54的配置
- 进程间通信系列 之 消息队列函数(msgget、msgctl、msgsnd、msgrcv)及其范例
- GDB用法
- Exists如些多焦