标签:
Date date=new Date();//现在时间 Date date1=new Date(1000);//格林威治时间1997/01/01开始算,后面的是毫秒 Calendar calendar=Calendar.getInstance();//获得一个月历 calendar.set(2016, 0,01); calendar.setTime(new Date());//setTime的时候才可以用new Date() int year=calendar.get(Calendar.YEAR), month=calendar.get(Calendar.MONTH)+1, day=calendar.get(Calendar.DAY_OF_MONTH), hour=calendar.get(Calendar.HOUR_OF_DAY), minute=calendar.get(Calendar.MINUTE), second=calendar.get(Calendar.SECOND); System.out.printf("%d,%d,%d,%d,%d,%d\n",year,month,day,hour,minute,second); System.out.println(date);
计算两个时间差的天数
比如2012/9/1和2016/7/1
Calendar calendar1=Calendar.getInstance(); Calendar calendar2=Calendar.getInstance(); calendar1.set(2012, 9,1); calendar2.set(2016, 7,1); long time1=calendar1.getTimeInMillis();//貌似是获得时间绝对值的函数 long time2=calendar2.getTimeInMillis(); System.out.println(Math.abs((time1-time2)/(1000*60*60*24)));
标签:
原文地址:http://www.cnblogs.com/vhyc/p/5945330.html