1.首先编写一个方法,
2.传入一个日期对象,返回一个字符串,
3.字符串结果就是前边的微信留言时间效果
代码:
public class G2 {
public static void main(String[] args) {
String msgs="你好,在干嘛";
System.out.printf(mn(msgs));
}
public static String mn(String msgs) {
long ss=1689246311841L;
System.out.printf("%tF %<tT:%s%n",ss,msgs);
long nn=System.currentTimeMillis();
long sss=(nn-ss)/1000;
long mm=sss/60;
long hh=mm/60;
long dd= hh/24;
String she="";
if (mm<1){
System.out.printf("刚刚:%s%n",msgs);
}else if(hh<1){
System.out.printf("%d分钟前:%s%n",mm,msgs);
} else if (dd<1) {
System.out.printf("%d小时前:%s%n",hh,msgs);
}else if (dd<10){
System.out.printf("%d天前:%s%n",dd,msgs);
}
else {
System.out.printf("%tF %<tT:%s%n",ss,msgs);
}
return she;
}
}