Calendar showing wrong date and time
final Calendar c = Calendar.getInstance();
Toast.makeText(alarm.this, " "+c.DAY_OF_MONTH+ " " +c.MONTH+ " " +c.YEAR ,
Toast.LENGTH_LONG).show();
this code is showing 05-02-01 as the date, instead of todays date (25-08-2011) C开发者_C百科an anybody tell me what is happening?
regards sandeep
Use the get
method to get the actual field values:
c.get(Calendar.DAY_OF_MONTH) ...
The value DAY_OF_MONTH
is actually a constant referencing the fields of the calendar object.
and, according to what Howard says in comment, you must add 1 to get the exact value for the month since it's coded between 0 and 11 :
Calendar c = Calendar.getInstance();
Toast.makeText(alarm.this, String.valueOf(c.get(Calendar.MONTH)+1)).show();
精彩评论