Bha*_*iya 14
你可以使用SimpleDateFormat.
获取当前日期的基础知识
DateFormat df = new SimpleDateFormat("MMM d, yyyy");
String now = df.format(new Date());
Run Code Online (Sandbox Code Playgroud)
要么
DateFormat df = new SimpleDateFormat("MM/dd/yy");
String now = df.format(new Date());
Run Code Online (Sandbox Code Playgroud)
编辑: 首先,你在String Formate中有约会.你必须转换成约会Formate.尝试下面的代码来做到这一点.你已经为String strThatDay和strTodaDay应用了相同的内容,你将获得两个Calender Object.
String strThatDay = "2012/11/27";
SimpleDateFormat formatter = new SimpleDateFormat("yyyy/MM/dd");
Date d = null;
try {
d = formatter.parse(strThatDay);//catch exception
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Calendar thatDay = Calendar.getInstance();
thatDay.setTime(d);
Run Code Online (Sandbox Code Playgroud)
之后尝试下面的代码从两个日期获取日期:
long diff = today.getTimeInMillis() - thatDay.getTimeInMillis(); //result in millis
long days = diff / (24 * 60 * 60 * 1000);
Run Code Online (Sandbox Code Playgroud)
试试看.希望它会对你有所帮助.