Could anyone show me how to get the curent date after clicking a button so that I could do something with it for example if you could get the year you could say somthing like this
if year % 4 = 0
{
it's a leap year
}
I also have a few other ideas for it.
Calendar cal = Calendar.getInstance();
final String TYPE = "YYYY";
SimpleDateFormat sdf = new SimpleDateFormat(TYPE);
String currentyear = sdf.format(cal.getTime());
Calendar cal = Calendar.getInstance();
int year = cal.get(Calendar.YEAR);
Alternative try this to get the current year.
Or alternately to above, if an int is more convenient,
Calendar cal = Calendar.getInstance();
int year = cal.get(Calendar.YEAR);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.