简体   繁体   English

Android日期选择器(获取当前日期)

[英]Android Date Picker (Getting current Date)

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, 或替代上述方法,如果使用int更方便,

Calendar cal = Calendar.getInstance();
int year = cal.get(Calendar.YEAR);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM