分享

发帖,计算什么时候发的java代码

 走墨 2014-09-24
public static String cntDateTime(Date dateTime){
String newDateTime="";
if(dateTime!=null){
Long ss=System.currentTimeMillis()-dateTime.getTime();
Long s=ss/1000;
if(s<=10){
newDateTime="刚刚";
}else if(s<=60){
newDateTime=s+"秒前";
}else if(s>60&&s<(60*60)){
newDateTime=s/60+"分钟前";
}else if(s>=(60*60)&&s<(60*60*24)){
Long se=DateFormater.StringToDate(DateFormater.DateToString(new Date(), "yyyy-MM-dd")+" 24:00:00", "yyyy-MM-dd HH:mm:ss").getTime();
Long sd=DateFormater.getAfterDay(DateFormater.StringToDate(DateFormater.DateToString(new Date(), "yyyy-MM-dd")+" 24:00:00", "yyyy-MM-dd HH:mm:ss"), -1).getTime();
if(dateTime.getTime()<=se&&dateTime.getTime()>sd){
newDateTime="今天"+DateFormater.DateToString(dateTime, "HH:mm");
}else{
newDateTime="昨天"+DateFormater.DateToString(dateTime, "HH:mm");;
}
}else{
int y=dateTime.getYear();
int oy=new Date().getYear();
if(y==oy){
newDateTime=DateFormater.DateToString(dateTime, "M月dd日 HH:mm");
}else{
newDateTime=DateFormater.DateToString(dateTime, "yyyy年MM月dd日 HH:mm");
}
}
}else{
newDateTime="不详";
}
return newDateTime;
}

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多