java如何将时间转换成文本_JAVA技术点系列:将时间转化成文字性描述

原标题:JAVA技术点系列:将时间转化成文字性描述

分享一段代码,将时间转化成文字性描述(刚刚,分钟前,小时前,天前,周前)

private String coverToShowTime(Date updateTime) {

SimpleDateFormat sf = new SimpleDateFormat(yyyy-MM-dd);

long time = (System.currentTimeMillis() - updateTime.getTime()) / 1000;

//小于60 秒显示刚刚

String result = sf.format(updateTime);

long temp = 0;

if (time 60) {

result = 刚刚;

//小于60分钟直接显示几分钟前

}else if( (temp = time/60) 60){

result = temp + 分钟前;

//小于24小时直接显示几小时前

}else if((temp = time/(60*60)) 24){

result = temp + 小时前;

//小于7天显示几天前

}else if((temp = time/(86400)) 7){

result = temp + 天前;

大于7天小于14天显示1周前

}else if((temp = time/(86400*7)) 2){

result = temp + 周前;

}

return result;

}

效果

4233017be3a43e974bb6a4d578d06fd1.png

责任编辑:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值