I am trying to get the timestamp.
This works.
final Calendar cal = new GregorianCalendar(tz);
final Timestamp ts = new Timestamp(cal.getTimeInMillis());
But, I don’t want to reinstantiate the variables each and every time, I need to get the timestamp. How can I do that?
I tried to do..
//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());
This doesn’t seem to work. Could you suggest?
Try
System.currentTimeMillis()to avoid creating a calendar.