直接上传代码:
import java.util.Calendar;
import java.text.SimpleDateFormat;
import java.text.ParseException;
public class CalendarDemo {
public static void main(String[] args) throws ParseException {
Calendar c = Calendar.getInstance();
int year = c.get(Calendar.YEAR);
int month = c.get(Calendar.MONTH);
int day = c.get(Calendar.DAY_OF_MONTH);
int hour = c.get(Calendar.HOUR_OF_DAY);
int minute = c.get(Calendar.MINUTE);
int second = c.get(Calendar.SECOND);
System.out.println("今天是:"+year+"年"+month+"月"+day+"日"+" "
+hour+":"+minute+":"+second);
String hDay = "2017/09/10 12:00:00";
String qDay = "2016/08/17 13:00:14";
long days = calcDays(hDay, qDay);
System.out.println(days);
}
public static long calcDays(String date1,String date2) throws ParseException {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/ss HH:mm:ss");
Calendar c = Calendar.getInstance();
c.setTime(sdf.parse(date1));
long time1 = c.getTimeInMillis();
c.setTime(sdf.parse(date2));
long time2 = c.getTimeInMillis();
return (time1-time2)/(24*3600*1000);
}
}
点击查看更多内容
3人点赞
评论
共同学习,写下你的评论
评论加载中...
作者其他优质文章
正在加载中
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦