how to get week day for given date for using Calendar in android studio -
here code:
// date birthday; gregoriancalendar birthday = new gregoriancalendar(); birthday.set(year_int,mo,da,0,0,0); int weekday = birthday.get(gregoriancalendar.day_of_week); string weekday = string.valueof(weekday -1); weekday = weekday.replace("0","sunday."); weekday = weekday.replace("1","monday."); weekday = weekday.replace("2","tuesday."); weekday = weekday.replace("3","wednesday."); weekday = weekday.replace("4","thursday."); weekday = weekday.replace("5","friday."); weekday = weekday.replace("6","saturday.");
what's wrong here? please me.
use joda-time instead.
datetime birthday = new datetime(year, mo,day, 0, 0, 0); datetimeformatter format = datetimeformat.forpattern("eeee"); string weekday = birthday.tostring(format);
will return day of week.
if want use calendar:
simpledateformat sdf = new simpledateformat("eeee"); calendar calendar = new gregoriancalendar(year, mo,day, 0, 0, 0); string weekday = sdf.format(calendar.gettime());
Comments
Post a Comment