1 public static long getSkewDaysByDate(String time){
 2         long days = 0;
 3         try {
 4             SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
 5             format.setLenient(false);
 6             Date time2 = format.parse(time);
 7             Date nowTime = new Date();
 8             days = gapDays(time2.getTime(), nowTime.getTime());
 9         } catch (ParseException e) {
10             // TODO Auto-generated catch block
11             e.printStackTrace();
12         }
13         return days;
14     }
15     
16     private final static long gapDays(long lastTime, long nowTime) {
17         long days = (long) ((nowTime + (8 * 3600000)) / (24 * 3600000) - (lastTime + (8 * 3600000)) / (24 * 3600000));
18         return days;
19     }
20     
21     public static void main(String[] args) {
22         long days = getSkewDaysByDate("2018-07-23 14:07:54");
23         System.out.println(days);
24     }

posted on 2018-07-24 16:58  小太阳Melody  阅读(160)  评论(0编辑  收藏  举报