我正在尝试获取时间戳。
这行得通。
final Calendar cal = new GregorianCalendar(tz);
final Timestamp ts = new Timestamp(cal.getTimeInMillis());
但是,我不想每次都重新实例化变量,我需要获取时间戳。我怎样才能做到这一点?
我试着做..
//instantiate the variables.
private final Calendar cal = new GregorianCalendar(tz);
private final Timestamp ts = new Timestamp(cal.getTimeInMillis());
Inside a method()
// trying to ask calendar to recalculate the time -- not working.
cal.setTimeZone(tz); // I tried cal.clear() but it is giving me time during 1970 which I don't want.
ts.setTime(cal.getTimeInMillis());
这似乎不起作用。你能建议吗?