Here is my 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 help 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 you want to use Calendar:
SimpleDateFormat sdf = new SimpleDateFormat("EEEE");
Calendar calendar = new GregorianCalendar(year, mo,day, 0, 0, 0);
String weekDay = sdf.format(calendar.getTime());
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.