2010-07-19 21 views
1

現在日期=新日期();java中的新Date對象是否包含當前日期?或者它是空的?

if (now.getTime() - leasedDate.getTime() > 21 * 1000 * 60 * 60 * 24) 
     throw new TooLate(); 
    leased.remove(x); 

我在看一些代碼示例,以上是它的一部分。有些事我不明白。名爲「now」的日期對象是否有當前日期和小時?因爲我認爲它在初始化時應該是空的,所以我不明白now.getTime()是如何工作的。

謝謝!從Java文檔

+4

你有*和* *的文檔資料.... – skaffman 2010-07-19 11:19:51

回答

5

Date對象包含一個long值,表示1970年以來的時間(以毫秒爲單位)。默認構造函數將其初始化爲System.currentTimeMillis()

11

報價 - 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.

所以回答你的問題是:是的,它包含了當前日期

0

是,

Date now = new Date(); 

包含當前的系統時間(對象創建的RAM中的確切時間)。

相關問題