public class TimeUtil { /** * 把一个时间戳转为描述性的文字 * 如果时间戳代表的时间是今天14:35 返回“14:35” * 如果时间戳代表的时间是昨天14:35 返回“昨天 14:35” * * 如果时间戳代表的时间是更往前的14:35 返回“xxxx-xx-xx 14:35” * * @param time 秒值 * @return */ public static String getTime(long time) { String result = ""; Calendar calendar = Calendar.getInstance(); int week = calendar.get(Calendar.DAY_OF_WEEK) - 1; //根据time与当前时间的差距计算差了多少天 long now = System.currentTimeMillis();//毫秒值 //计算差了多少天 int day = (int) (now / 1000 / 3600 / 24 - time / 1000 / 3600 / 24); if (week!=0){ int dayCha = week - day; if (day == 0) { result = new SimpleDateFormat("HH:mm").format(time); return result; } if (day == 1) { result = "昨天 " + new SimpleDateFormat("HH:mm").format(time); return <
时间转换工具类
最新推荐文章于 2019-05-22 21:48:42 发布