求出2008年8月27日和2008-08-24相差多少天?
题目10: 2008年8月27日和2008-08-24相差多少天?
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
public class Test {
public static void main(String[] args) {
Date date = null;
Calendar cal = Calendar.getInstance();
SimpleDateFormat myFormatter = new SimpleDateFormat("yyyy-MM-dd");
try {
date = myFormatter.parse("2008-08-27");
} catch (ParseException e) {
e.printStackTrace();
}
Date mydate = null;
try {
mydate = myFormatter.parse("2008-08-24");
} catch (ParseException e) {
e.printStackTrace();
}
long dayl = (date.getTime() - mydate.getTime())
/ (24l * 60l * 60l * 1000l);
System.out.println("天数是 is " + dayl);
}
}
更多内容请见原文,原文转载自:https://blog.csdn.net/qq_44639795/article/details/103122953