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     }
  • 相关阅读:
    3.5.3 数据排序;重复数值、缺失值处理
    3.5.1 pandas基础
    3.3 numpy
    数据准备和特征工程
    2.4函数
    2.3语句与控制流
    2.2数据结构与序列
    2.1Python基础知识
    五、MySQL安装
    四、Hadoop HA 集群搭建
  • 原文地址:https://www.cnblogs.com/jinglecode/p/5175214.html
Copyright © 2011-2022 走看看