我想獲得當前時間(即IST)和存儲在DB(EST)中的時間的差異。爲了達到這個目的,我想在計算差異之前將當前時間轉換爲EST。但它不工作。在以下方法中,當地時間 不僅僅轉換爲EST。你能否建議我以更好的方式來做到這一點? 的getModifiedDate
返回類型是java.sql.Timestamp
和列的數據類型 是DATE
兩個不同時區的時差
代碼:
Calendar cal = new GregorianCalendar(TimeZone.getTimeZone("EST"));
cal.setTimeInMillis(System.currentTimeMillis());
cal.getTimeInMillis() - emp.getModifiedDate().getTime();
我試圖用SimpleDateFormat
做到這一點,但我不知道如何進行用這種方法。
如果您可以提供的代碼片段,將有助於
「emp」從哪裏來? – Juan
'emp'是映射到表的實體類'Employee'的obj引用 – Rehman
'emp.getModifiedDate()。getTime();'? –