对日期时间的抽象?Date/Calendar?
Date类从jdk1.0开始存在,大部分构造器和方法均已过时,不再推荐使用,推荐使用Calendar
Date类源码?
public class Date
implements java.io.Serializable, Cloneable, Comparable<Date>
{
private static final long serialVersionUID = 7523967970034938905L;
public Date() {//推荐使用的构造器
this(System.currentTimeMillis());
}
public Date(long date) {//推荐使用的构造器
fastTime = date;
}
@Deprecated
public Date(int year, int month, int date) {//不推荐使用的构造器
this(year, month, date, 0, 0, 0);
}
@Deprecated
public Date(int year, int month, int date, int hrs, int min) {//不推荐使用的构造器
this(year, month, date, hrs, min, 0);
}
@Deprecated
public Date(int year, int month, int date, int hrs, int min, int sec) {//不推荐使用的构造器
int y = year + 1900;
// month is 0-based. So we have to normalize month to support Long.MAX_VALUE.
if (month >= 12) {
y += month / 12;
month %= 12;
} else if (month < 0) {
y += CalendarUtils.floorDivide(month, 12);
month = CalendarUtils.mod(month, 12);
}
BaseCalendar cal = getCalendarSystem(y);
cdate = (BaseCalendar.Date) cal.newCalendarDate(TimeZone.getDefaultRef());
cdate.setNormalizedDate(y, month + 1, date).setTimeOfDay(hrs, min, sec, 0);
getTimeImpl();
cdate = null;
}
@Deprecated
public Date(String s) {//不推荐使用的构造器
this(parse(s));
}
public Object clone() {//实现Cloneable接口,可以实现自我克隆
Date d = null;
try {
d = (Date)super.clone();