Code example for TimeZone

Methods: getOffset

0
     * @param date date to convert. 
     * @return your time zone date time. 
     */ 
    public static Date convertToTimeZoneFromDefault(TimeZone targetTimeZone, Date date) {
    	TimeZone defaultTz = TimeZone.getDefault();
    	Integer rawOffset = new Integer(defaultTz.getOffset(date.getTime()) - targetTimeZone.getOffset(date.getTime()));
    	 
    	return new Date(date.getTime() - rawOffset);
    } 
     
    /** 
     * Convert from client (time zone) time to your local time. 
     *  
     * @param targetTimeZone time zone converting from. 
     * @param date date to convert. 
     * @return your local date time. 
     */ 
    public static Date convertFromTimeZoneToDefault(TimeZone targetTimeZone, Date date) {
    	TimeZone defaultTz = TimeZone.getDefault();
    	Integer rawOffset = new Integer(defaultTz.getOffset(date.getTime()) - targetTimeZone.getOffset(date.getTime()));
Experience pair programming with AI  Get Codota for Java