java - conversion to GMT giving problems during DST -
i facing problem in our existing application time entered employee (from org/store using time clock application) first converted gmt , stored in db. , displaying back, time in gmt converted store local time zone , displayed. in of cases works fine not when time zone moves dst , vice versa.
let me more specific. suppose standard time zone of store gmt-8 , employee punches @ 08:00 in morning, time converted gmt gives 16:00 , stored in db. conversion process first converts 08:00 store local time somehow gives 17:00 cet , 17:00 cet converted gmt gives 16:00 cet.
but if take example of 31 march when dst happens 02:00 becomes 03:00 am. suppose emplyoee punches @ 18:00 (on 30 march) returns me 04:00 cest during first conversion local , when convert gmt gives 03:00 cest. while converting gives 19:00 not correct. design says local times converted utc , stored in db if still utc should store 02:00 , not 03:00 because gmt/utc not have dst.
the code used conversion is:
step 1
final date localpunchdatetime = r3valconverter.convertfromtimezone(tedata.m_dttm, timezone.gettimezone("gmt-8"));
step 2
tedata.m_dttm = r3valconverter.converttogmt( localpunchdatetime );
r3valconverter.java
public static date convertfromtimezone(final date dtsrc, final timezone tzsrc) { final sisdatetime dttmtemp = new sisdatetime(dtsrc, timezone.getdefault()); final sisdatetime dttmsrc = new sisdatetime( dttmtemp.getyear(), dttmtemp.getmonth(), dttmtemp.getdate(), dttmtemp.gethour(), dttmtemp.getminute(), dttmtemp.getsecond(), tzsrc ); return dttmsrc.todate(); }
sisdatetime
gregoriancalendar m_cal; public sisdatetime(date dt, timezone tz) throws sisdatetimeexception { m_cal = new gregoriancalendar(tz); m_cal.settime(dt); resetmillis(); }
the other sisdatetime method using same gregoriancalendar.
i appreciate in regard. assuming here have problem here in first step dont know solution @ moment.
you have store utc + current offset in seconds local time utc in db. if want preserve local time, need pair (utc time, offset)
you use timezonewithoffsetfromgmt
(or simmiliar named)
Comments
Post a Comment