java - How to replace getDate() from the type Date which is deprecated? -


i have existing program have correct . contains these lines :

        date startdate = new date();         int day = startdate.getdate() - 1; 

but getdate() type date deprecated have change using calender. tried :

calendar startdate = calendar.getinstance(); startdate.add(calendar.date, -1); int day= startdate.gettime(); 

but results following error :

type mismatch: cannot convert date int

if want day in month use this:

int day= startdate.get(calendar.day_of_month); 

if want day in week use this:

int day= startdate.get(calendar.day_of_week); 

also careful day of week, because day 0 sunday not monday.

field number , set indicating day of week. field takes values sunday, monday, tuesday, wednesday, thursday, friday, , saturday.


Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -