tags:

views:

141

answers:

4

Hey,

    Date now = new Date();

    if (now.getTime() - 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!

+9  A: 

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.

Petar Minchev
+2  A: 

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

rsp
A: 

Yes,

Date now = new Date();

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

IvanR