已经标注@Deprecated的方法我就不列了。
一、获取Date对象
public Date()
public Date(long date)
// 无参构造器源码
public Date() {
this(System.currentTimeMillis());
}
二、方法
1.判断两个时间的先后
public boolean before(Date when)
public boolean after(Date when)
2.返回一个副本
public Object clone()
3.比较两个时间的先后
// 应该是实现了Comparable的方法
public int compareTo(Date anotherDate) {
long thisTime = getMillisOf(this);
long anotherTime = getMillisOf(anotherDate);
return (thisTime<anotherTime ? -1 : (thisTime==anotherTime ? 0 : 1));
}
4.返回当前时间的毫秒值
public long getTime()
5.设置时间
// 源码
public void setTime(long time) {
fastTime = time;
cdate = null;
}
6.equals
public boolean equals(Object obj) {
return obj instanceof Date && getTime() == ((Date) obj).getTime();
}