Package model

Examples of model.MyDate


   */
  @SuppressWarnings("unused")
  public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    int year, month, day;
    MyDate next = new MyDate();
    MyDate previous = new MyDate();
    try {
      year = in.nextInt();
      month = in.nextInt();
      day = in.nextInt();
    } catch (Exception e) {
      System.out.println("请输入正确的数字");
      return;
    }
    if (!isCorrect(year, month, day)) {
      System.out.println("请输入正确的日期");
      return;
    }

    if (!isFirst(year, month, day) && !isLast(year, month, day)) {
      next.setMonth(month);
      next.setYear(year);
      next.setDay(day + 1);
      previous.setYear(year);
      previous.setMonth(month);
      previous.setDay(day - 1);

    } else if (isFirst(year, month, day)) {
      if (!isFirstYear(year, month, day)) {
        previous.setYear(year);
        previous.setMonth(month - 1);
        if (isLeapYear(year)) {
          previous.setDay(days29[month - 2]);
        } else {
          previous.setDay(days28[month - 2]);
        }
      } else {
        previous.setYear(year - 1);
        previous.setMonth(12);
        previous.setDay(31);
      }
      next.setMonth(month);
      next.setYear(year);
      next.setDay(day + 1);
    } else if (isLast(year, month, day)) {
      if (!isLastYear(year, month, day)) {
        next.setMonth(month + 1);
        next.setYear(year);
        next.setDay(1);

      } else {
        next.setMonth(1);
        next.setYear(year + 1);
        next.setDay(1);
      }
      previous.setYear(year - 1);
      previous.setMonth(month);
      previous.setDay(day - 1);
    }
    System.out.println("下一天是" + next);
    System.out.println("前一天是" + previous);
    return;
  }
View Full Code Here


  }

  @Test
  public void testGetNext() {
    // System.out.println(getDate(1987, 88));
    System.out.println(getNext(new MyDate(1989, 2, 1)));
    System.out.println(getNext(new MyDate(1998, 3, 5)));
    System.out.println(getNext(new MyDate(2012, 6, 7)));
  }
View Full Code Here

  }

  @Test
  public void testGetPrevious() {
    // System.out.println(getDate(1987, 88));
    System.out.println(getPrevious(new MyDate(1989, 2, 1)));
    System.out.println(getPrevious(new MyDate(1998, 3, 5)));
    System.out.println(getPrevious(new MyDate(2012, 6, 7)));
  }
View Full Code Here

    all += day;
    return all;
  }

  public MyDate getDate(int year, int days) {
    MyDate myDate = new MyDate();
    int m = 0;
    if ((days > 365 && !isLeapYear(year))
        || (days > 366 && isLeapYear(year))) {
      myDate.setYear(year++);
      myDate.setMonth(1);
      myDate.setDay(1);
      return myDate;
    }
    do {
      days = days - this.days[m++];
      if (m == 2 && !isLeapYear(year)) {
        days++;
      }
    } while (days > 0);
    myDate.setDay(this.days[--m] + days);
    myDate.setMonth(m);
    myDate.setYear(year);
    return myDate;

  }
View Full Code Here

  }

  public MyDate getInput() {
    Scanner in = new Scanner(System.in);
    MyDate myDate = new MyDate();
    try {
      myDate.setYear(in.nextInt());
      myDate.setMonth(in.nextInt());
      myDate.setDay(in.nextInt());
    } catch (Exception e) {
      System.out.println("请输入正确的数字");
      return null;
    }
    return myDate;
View Full Code Here

TOP

Related Classes of model.MyDate

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.