开发者

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜