我正在尝试运行这个小代码来返回一个8位integer
,以便稍后在for-loop
中用作搜索功能。问题是它不会返回searchDateToday
的任何值。我错过了什么吗?
final Calendar cal = Calendar.getInstance();
SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd");
DateToday = formatter.format(cal.getTime()); // YYYYMMDD form -
// Example: 20111010
// = October 10,
// 2011
int searchDateToday = Integer.parseInt(DateToday);
答案 0 :(得分:2)
您忘记使用Date对象:
final Calendar cal = Calendar.getInstance();
SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd");
DateToday = formatter.format(new Date(cal.getTime()));
// YYYYMMDD form -// Example: 20111010 // = October 10, // 2011
int searchDateToday = Integer.parseInt(DateToday);
答案 1 :(得分:0)
用它来获取今天的日期
String currentDate = DateFormat.getDateInstance().format(new Date());
tv_date.setText(currentDate); // tv_date is TextView