【发布时间】:2018-04-09 18:40:33
【问题描述】:
我得到的当前日期如下:
public void getCurrentDate(View view) {
Calendar calendar = Calendar.getInstance();
SimpleDateFormat mdformat = new SimpleDateFormat("yyyy / MM / dd ");
String strDate = "Current Date : " + mdformat.format(calendar.getTime());
display(strDate);
}
private void display(String num) {
TextView textView = (TextView) findViewById(R.id.current_date_view);
textView.setText(num);
}
但我想检查日期是否是今天的日期。但我不知道如何检查。
【问题讨论】:
-
不幸的是,Android 会给你系统日期,可以很容易地从设置中更改。要获得实际日期,您需要使用互联网验证
-
顺便考虑扔掉长期过时且臭名昭著的麻烦
SimpleDateFormat和朋友,并将ThreeTenABP添加到您的Android项目中,以便使用java.time,现代Java日期和时间API .使用起来感觉好多了。
标签: android date date-comparison