You need to get the timeZoneOffSet from browser by using the following javascript snippet:
<script type="text/javascript"> var dateObj = new Date() var timeZoneOffsetInMins = dateObj.getTimezoneOffset(); document.getElementById("bTimeZoneOffset").value = timeZoneOffsetInMins; </script> <form> <input id="bTimeZoneOffset" type="hidden" /> </form>
Java Class Method:::private String getClientDateTime(String strFormat, long timeZoneOffSet){ SimpleDateFormat sdf = new SimpleDateFormat(strFormat); TimeZone timeZone= TimeZone.getTimeZone("UTC"); if(timeZoneOffSet < 0){ timeZoneOffSet = -1 * timeZoneOffSet; } timeZoneOffSet = timeZoneOffSet * 60000; timeZone.setRawOffset(timeZoneOffSet); sdf.setTimeZone(timeZone); return sdf.format(new Date()); }
You are an amazing coder.. Did anybody ever nickname you "Houdini of e-Commerce" ???
ReplyDelete