zoukankan      html  css  js  c++  java
  • Java返回距离当前时间段

     1     /**
     2      * 计算该时间离当前时间的差距
     3      * @param time 格式为:yyyy-MM-dd HH:mm:ss
     4      * @return
     5      */
     6     public static String getShortTime(String time) {
     7         Date date = getDateByString(time);
     8         return getShortTime(date);
     9     }
    10     
    11     public static String getShortTime(Date date) {
    12         String shortstring = null;
    13         long now = Calendar.getInstance().getTimeInMillis();
    14         if(date == null) return shortstring;
    15         long deltime = (now - date.getTime())/1000;
    16         if(deltime > 365*24*60*60) {
    17             shortstring = (int)(deltime/(365*24*60*60)) + "年前";
    18         } else if(deltime > 7*24*60*60) {
    19             shortstring = (int)(deltime/(7*24*60*60)) + "周前";
    20         } else if(deltime > 24*60*60) {
    21             shortstring = (int)(deltime/(24*60*60)) + "天前";
    22         } else if(deltime > 60*60) {
    23             shortstring = (int)(deltime/(60*60)) + "小时前";
    24         } else if(deltime > 60) {
    25             shortstring = (int)(deltime/(60)) + "分钟前";
    26         } else if(deltime > 10) {
    27             shortstring = deltime + "秒前";
    28         } else {
    29             shortstring = "刚刚";
    30         }
    31         return shortstring;
    32     }
  • 相关阅读:
    01
    王天宇0703作业
    0706作业
    0705作业
    0704作业
    0703作业
    数据库死锁语句脚本
    项目问题 : 尝试读取或写入受保护的内存。这通常指示其他内存已损坏
    工厂模式(Factory Patter)
    修改DevExpress中英文提示,将英文改为中文
  • 原文地址:https://www.cnblogs.com/jinglecode/p/5175214.html
Copyright © 2011-2022 走看看