的JavaDoc Date类规定,正开始日期与时间(毫秒)构造
public Date(long date)
Allocates a Date object and initializes it to represent the specified number of
milliseconds since the standard base time known as "the epoch", namely January 1, 1970,
00:00:00 GMT.
下面是一个使用日期计算的毫秒数(长毫秒)构造函数计算1月24日和1月25日期代码
public static void main(String[] args) throws java.text.ParseException {
long milliSecFor25 = (24*60*60*24*1000);
long milliSecFor26 = (25*60*60*24*1000);
Date dateJan25 = new Date(milliSecFor25);
Date dateJan26 = new Date(milliSecFor26);
System.out.println("Date for Jan 25:" + dateJan25);
System.out.println("Date for Jan 26:" + dateJan26);
}
上执行下面的代码我得到下面的输出,
Date for Jan 25: Sun Jan 25 05:30:00 IST 1970
Date for Jan 26: Sun Dec 07 12:27:12 IST 1969
这是不正确的。有人可以解释为什么不`吨我得到年01月25
正确的日期
,我认为你应该检查你的“暧昧”的使用以供将来参考 - 我想你只是说“不正确”在这里,这是不一样的东西。 –
@JonSkeet:雅好感谢,我将在这里改变它太 –