0

我不想担心闰年,但我担心我所拥有的基础是否正确。

导入 javax.swing.Spring;

public class Date 
{

    /**
     * A variable to hold the day value
     */
    private int day;

    /**
     * A variable to hold the month value
     */
    private int month;

    /**
     * A variable to hold the year value
     */
    private int year;

    /**
     * the date in the form m/d/yyyy
     */
    private String stringDate;

    /**
     * To figure out which month it is
     */
    private boolean isThirtyDays, isThirtyOneDays, isTwentyEightDays;

    /**
     * advances the date by one day based on the month
     */
    private void advance()
    {

        if(month == 9 || month == 4 || month == 6 || month == 11)
        {
            if(day == 30)
            {
                month++;
                day = 1;
            }

            else
                day++;
        }

        if(month == 1 || month == 3 || month == 5 || month == 7 || month == 8
                || month == 10 || month == 12)
        {
            if(day == 31)

            {
                month++;
                day = 1;

                if(month == 12)

                {
                    month = 1;
                    day = 1;
                    year++;
                }
            }

            else
                day++;
        }

        if(month == 2)

        {
            if(day == 28)

            {
                month++;
                day = 1;
            }

            else
                day++;
        }
    }

    /**
     * Takes the year, month and day and displays it as m/d/yyyy
     * Before it does it though, it changes all the ints to strings 
     */
    private String toString(int yearString, int monthString, int dayString)
    {

        stringDate = (Integer.toString(monthString) + "/" + Integer.toString(dayString)
                + "/" + Integer.toString(yearString));

        return stringDate;
    }

}

我想知道的是所有|| 陈述实际上是正确的,或者是否有一种方法需要更少的工作。我对 java 也很陌生,想知道在 Eclipse 环境中发送文本的最佳方法是什么。

4

1 回答 1

0

为什么不使用日历?

Calendar time = Calendar.getInstance();

time.add(Calendar.DAY,+1)

于 2013-09-05T20:27:09.927 回答