清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>
仿新浪微博格式化时间.现在项目中用到,适用于web项目等等,即时通信工具等用于显示时间试用。public static String getInterval(Date createAt) { // 定义最终返回的结果字符串。 String interval = null; long millisecond = new Date().getTime() - createAt.getTime(); long second = millisecond / 1000; if (second <= 0) { second = 0; } //*--------------微博体(标准) if (second == 0) { interval = "刚刚"; } else if (second < 30) { interval = second + "秒以前"; } else if (second >= 30 && second < 60) { interval = "半分钟前"; } else if (second >= 60 && second < 60 * 60) {//大于1分钟 小于1小时 long minute = second / 60; interval = minute + "分钟前"; } else if (second >= 60 * 60 && second < 60 * 60 * 24) {//大于1小时 小于24小时 long hour = (second / 60) / 60; if (hour <= 3) { interval = hour + "小时前"; } else { interval = "今天" + getFormatTime(createAt, "HH:mm"); } } else if (second >= 60 * 60 * 24 && second <= 60 * 60 * 24 * 2) {//大于1D 小于2D interval = "昨天" + getFormatTime(createAt, "HH:mm"); } else if (second >= 60 * 60 * 24 * 2 && second <= 60 * 60 * 24 * 7) {//大于2D小时 小于 7天 long day = ((second / 60) / 60) / 24; interval = day + "天前"; } else if ( second <= 60 * 60 * 24 * 365 && second >= 60 * 60 * 24 * 7) {//大于7天小于365天 interval = getFormatTime(createAt, "MM-dd HH:mm"); } else if (second >= 60 * 60 * 24 * 365) {//大于365天 interval = getFormatTime(createAt, "yyyy-MM-dd HH:mm"); } else { interval = "0"; } }