import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.GregorianCalendar;
public class Test{
  public static void main(String[] args) throws ParseException{
    DateFormat dateFormat=new SimpleDateFormat("yyyy-MM-dd");
    GregorianCalendar gc=new GregorianCalendar(1000,1,29);
    Date date=gc.getTime();
    String sdate=dateFormat.format(date);
    System.out.println(sdate);
  }
}1000-02-29这一天真的存在么?
按照闰年规则,1000年应该不是闰年,但是sun API却输出了这一天!!!

解决方案 »

  1.   

    到Google 翻翻万年历去。看看
      

  2.   

    我从文档给你找到答案了
    GregorianCalendar 实现的是儒略历。格里高利历和儒略历之间的唯一区别就是闰年规则。儒略历指定每 4 年就为闰年,而格里高利历则忽略不能被 400 整除的世纪年。 文档原文:
    The only difference between the Gregorian and the Julian calendar is the leap year rule. The Julian calendar specifies leap years every four years, whereas the Gregorian calendar omits century years which are not divisible by 400. 
      

  3.   

    再补充,GregorianCalendar 实现了格里高利历和儒略历,以1582年10月15号为区分
    在1582年之前的采用儒略历(Julian)--闰年以4整除为标准,之后的用格里高利历(Gregorian)--闰年为被4整除,并且百年的能被400整除。
    判断闰年源码:    public boolean isLeapYear(int year) {
    if ((year & 3) != 0) {
        return false;
    }        if (year > gregorianCutoverYear) {
                return (year%100 != 0) || (year%400 == 0); // Gregorian
    }
    if (year < gregorianCutoverYearJulian) {
                return true; // Julian
    }
    boolean gregorian;
    // If the given year is the Gregorian cutover year, we need to
    // determine which calendar system to be applied to February in the year.
    if (gregorianCutoverYear == gregorianCutoverYearJulian) {
        BaseCalendar.Date d = getCalendarDate(gregorianCutoverDate); // Gregorian
        gregorian = d.getMonth() < BaseCalendar.MARCH;
    } else {
        gregorian = year == gregorianCutoverYear;
    }
    return gregorian ? (year%100 != 0) || (year%400 == 0) : true;
        }
      

  4.   

    1582-10-5到1582-10-14
    这10天不存在,虽然看完上面的说法,又翻了API文档已经大概了解了,不过还是非常新鲜,从来也没想到过有这样的事情!!!
      

  5.   

    (year%4==0&&year%100!=0)||year%400==0
      

  6.   

    顶,确实不错,不过一些小的细节问题,不是我们知道的,SUN公司还是有自己的实力的。像这样的问题,如果LZ不说出来我可能一辈子都不知道,但我知道也对我帮助不大。
      

  7.   

    if ((year & 3) != 0) {
            return false;
        }SUN还真是细节不错啊。