开发者

Does a new Date Object in java contain the current date? Or is it empty?

Date now = new Date();

    if (now.getTime(开发者_JAVA技巧) - leasedDate.getTime() > 21 * 1000 * 60 * 60 * 24)
        throw new TooLate();
    leased.remove(x);

I'm looking at some code examples and above is a part of it. There's something I don't understand. Does the date object called "now" have the current date and hour in it? Because I thought it should be empty when it's initialised so I don't understand how now.getTime() can work.

Thanks!


Quote from Java Docs - new Date() - Allocates a Date object and initializes it so that it represents the time at which it was allocated, measured to the nearest millisecond.

So the answer to your question is: Yes, it contains the current date.


The Date object contains a long which represents the time in milliseconds since 1970. The default constructor initialised it from System.currentTimeMillis().


http://download.oracle.com/docs/cd/E17476_01/javase/1.5.0/docs/api/java/util/Date.html#Date()

Yes it does.


Yes,

Date now = new Date();

contains the current system time (the exact time of the object creation in RAM).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜