- public static void main(String[] args) {
- Calendar c=Calendar.getInstance();
- int y=2016;//年
- int M=1;//月
- int d=1;//日
- int H=0;//时
- int m=0;//分
- int s=0;//秒
- c.set(Calendar.YEAR, y);
- c.set(Calendar.MONTH, M-1);
- c.set(Calendar.DATE, d);
- c.set(Calendar.HOUR_OF_DAY, H);
- c.set(Calendar.MINUTE, m);
- c.set(Calendar.SECOND, s);
- Calendar now=Calendar.getInstance();
- long aTime=now.getTimeInMillis();
- long bTime=c.getTimeInMillis();
- long cTime=aTime-bTime;
- long sTime=cTime/1000;//时间差,单位:秒
- long mTime=sTime/60;
- long hTime=mTime/60;
- long dTime=hTime/24;
- SimpleDateFormat f=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- System.out.println("当前时间:"+f.format(now.getTime()));
- System.out.println("设定时间:"+f.format(c.getTime()));
- System.out.println("时间差:"+dTime+"天"+hTime%24+"时"+mTime%60+"分"+sTime%60+"秒");
- }