我正在做一个公历项目,我必须从今天和我生日的星期几打印 100 天。该程序显示一天,但它是错误的一天。你们能帮我解决这个问题吗?谢谢!
import java.util.GregorianCalendar;
public class Gregorian {
public static void main(String[] args)
{
Day today = new Day();
System.out.print("Today: ");
System.out.println(today.toString());
GregorianCalendar Date = new GregorianCalendar();
Date.add(GregorianCalendar.DAY_OF_MONTH, 100);
CalendarUtils utils = new CalendarUtils();
String day = utils.getWeekday(Date.get(GregorianCalendar.DAY_OF_WEEK));
int year=Date.get(GregorianCalendar.YEAR);
int month=Date.get(GregorianCalendar.MONTH);
int dayof=Date.get(GregorianCalendar.DAY_OF_MONTH);
System.out.println("100 days from today: " + year + "/" + month + "/" + dayof + " which is a: " + day);
GregorianCalendar Birthday = new GregorianCalendar(2012,1,1);
String Bday = utils.getWeekday(Birthday.get(GregorianCalendar.DAY_OF_WEEK ));
System.out.println("Weekday of my Birthday: " + Bday );
Birthday.add(GregorianCalendar.DAY_OF_MONTH, 10000);
int Byear=Birthday.get(GregorianCalendar.YEAR);
int Bmonth=Birthday.get(GregorianCalendar.MONTH);
int Bdayof=Birthday.get(GregorianCalendar.DAY_OF_MONTH);
System.out.println("10000 days from my Birthday: " + Byear + "/" + Bmonth + "/" + Bdayof);
这是 CalendarUtils
import java.util.GregorianCalendar;
public class CalendarUtils
{
/**
Returns the String for GregorianCalendar DAY_OF_WEEK
*/
public String getWeekday(int day_of_week)
{
String day = "";
if (day_of_week == GregorianCalendar.SUNDAY)
{
day = "Sunday";
}
else if (day_of_week == GregorianCalendar.MONDAY)
{
day = "Monday";
}
else if (day_of_week == GregorianCalendar.TUESDAY)
{
day = "Tuesday";
}
else if (day_of_week == GregorianCalendar.WEDNESDAY)
{
day = "Wednesday";
}
else if (day_of_week == GregorianCalendar.THURSDAY)
{
day = "Thursday";
}
else if (day_of_week == GregorianCalendar.FRIDAY)
{
day = "Friday";
}
else if (day_of_week == GregorianCalendar.SATURDAY)
{
day = "Saturday";
}
return day;
}
/**
Returns the string of GregorianCalendar MONTH
*/
public String getMonth(int month)
{
String monthStr = "";
if (month == GregorianCalendar.JANUARY)
{
monthStr = "January";
}
else if (month == GregorianCalendar.FEBRUARY)
{
monthStr = "February";
}
else if (month == GregorianCalendar.MARCH)
{
monthStr = "March";
}
else if (month == GregorianCalendar.APRIL)
{
monthStr = "April";
}
else if (month == GregorianCalendar.MAY)
{
monthStr = "May";
}
else if (month == GregorianCalendar.JUNE)
{
monthStr = "June";
}
else if (month == GregorianCalendar.JULY)
{
monthStr = "July";
}
else if (month == GregorianCalendar.AUGUST)
{
monthStr = "August";
}
else if (month == GregorianCalendar.SEPTEMBER)
{
monthStr = "September";
}
else if (month == GregorianCalendar.OCTOBER)
{
monthStr = "October";
}
else if (month == GregorianCalendar.NOVEMBER)
{
monthStr = "November";
}
else if (month == GregorianCalendar.DECEMBER)
{
monthStr = "December";
}
return monthStr;
}
}