Date nowTime = new Date(System.currentTimeMillis()); SimpleDateFormat sdFormatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS"); String ret = sdFormatter.format(nowTime); SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS"); java.util.Date now = df.parse(ret); java.util.Date date=df.parse(shijian); long l=now.getTime()-date.getTime(); long day=l/(24*60*60*1000); long hour=(l/(60*60*1000)-day*24); long min=((l/(60*1000))-day*24*60-hour*60); long s=(l/1000-day*24*60*60-hour*60*60-min*60); System.out.println(""+day+"天"+hour+"小時"+min+"分"+s+"秒"); int a=(int)(day+hour+min);
對時間進行加減,來判斷數據庫取到的 shijian這個值 和系統當前時間相差多少java