java - Only default values are returned in Calendar object in android. Why? -
i have set date calendar object in way...
calendar lastcheckup = calendar.getinstance(); lastcheckup.set(year, month+1, day);
now, when print out in console using
system.out.println(lastcheckup);
i correct values...
07-18 11:59:13.903: i/system.out(1717): java.util.gregoriancalendar[time=1365834504001,arefieldsset=true,lenient=true,zone=asia/calcutta,firstdayofweek=1,minimaldaysinfirstweek=1,era=1,year=2013,month=3,week_of_year=15,week_of_month=2,day_of_month=13,day_of_year=103,day_of_week=7,day_of_week_in_month=2,am_pm=0,hour=11,hour_of_day=11,minute=58,second=24,millisecond=1,zone_offset=19800000,dst_offset=0]
so i'm assuming values set correctly in calendar object.
but when try access using
mtextviewlastcheckdate.settext(new stringbuilder().append(lastcheckup.day_of_month) .append("/").append(lastcheckup.month).append("/").append(lastcheckup.year) .append(" "));
i default values...
that is, textview gives output of 5/2/1
what doing wrong?
you're using lastcheckup.month
, lastcheckup.day_of_month
etc. constant fields - access values specific calendar, need
int month = lastcheckup.get(calendar.month);
etc. read documentation of calendar
more details how you're meant use it.
however, need understand months 0-based in calendar
, still wouldn't right. also, want 0-pad day , month. you'd much better off using simpledateformat
you.
// not sure why want space @ end, but... dateformat format = new simpledateformat("dd/mm/yyyy "); mtextviewlastcheckdate.settext(format.format(lastcheckup.gettime());
you should consider time zone , locale want use, too. above code uses default.
edit: note line:
lastcheckup.set(year, month+1, day);
is wrong. don't know month
meant here, in set
call should in range 0-11 inclusive (assuming gregorian calendar).
Comments
Post a Comment