Reputation: 27
I'm trying to run this little code to return a eight-digit integer
to be used in a for-loop
later on as a search function. Problem is that it doesn't return any values for searchDateToday
. Am I missing something?
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);
Upvotes: 0
Views: 187
Reputation: 22064
You forgot to use the Date object:
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);
Upvotes: 2
Reputation: 22493
use this for getting today date
String currentDate = DateFormat.getDateInstance().format(new Date());
tv_date.setText(currentDate); // tv_date is TextView
Upvotes: 0