sandeep
sandeep

Reputation: 947

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) Can anybody tell me what is happening?

regards sandeep

Upvotes: 0

Views: 1108

Answers (2)

Darkendorf
Darkendorf

Reputation: 473

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();

Upvotes: 0

Howard
Howard

Reputation: 39217

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.

Upvotes: 3

Related Questions