您必须自己处理,方法是在Test类中使用Date实例成员,并使用当前Date在构造函数(或其声明中)中初始化它.
public class Test {
Date date = new Date ();
public Date getCreationDate ()
{
return date;
}
}
Run Code Online (Sandbox Code Playgroud)
不,对象没有隐式时间戳.如果您需要知道,那么将一个实例变量添加到您的类中.
public class Test {
private final Date creationDate = new Date();
public Date getCreationDate() {
return creationDate; // or a copy of creation date, to be safe
}
}
Run Code Online (Sandbox Code Playgroud)