List of usage examples for java.util TimeZone getDSTSavings
public int getDSTSavings()
From source file:com.cloud.api.ApiResponseHelper.java
public String getDateStringInternal(Date inputDate) { if (inputDate == null) { return null; }/*from ww w .j av a 2 s . c om*/ TimeZone tz = _usageSvc.getUsageTimezone(); Calendar cal = Calendar.getInstance(tz); cal.setTime(inputDate); StringBuilder sb = new StringBuilder(32); sb.append(cal.get(Calendar.YEAR)).append('-'); int month = cal.get(Calendar.MONTH) + 1; if (month < 10) { sb.append('0'); } sb.append(month).append('-'); int day = cal.get(Calendar.DAY_OF_MONTH); if (day < 10) { sb.append('0'); } sb.append(day); sb.append("'T'"); int hour = cal.get(Calendar.HOUR_OF_DAY); if (hour < 10) { sb.append('0'); } sb.append(hour).append(':'); int minute = cal.get(Calendar.MINUTE); if (minute < 10) { sb.append('0'); } sb.append(minute).append(':'); int seconds = cal.get(Calendar.SECOND); if (seconds < 10) { sb.append('0'); } sb.append(seconds); double offset = cal.get(Calendar.ZONE_OFFSET); if (tz.inDaylightTime(inputDate)) { offset += (1.0 * tz.getDSTSavings()); // add the timezone's DST // value (typically 1 hour // expressed in milliseconds) } offset = offset / (1000d * 60d * 60d); int hourOffset = (int) offset; double decimalVal = Math.abs(offset) - Math.abs(hourOffset); int minuteOffset = (int) (decimalVal * 60); if (hourOffset < 0) { if (hourOffset > -10) { sb.append("-0"); } else { sb.append('-'); } sb.append(Math.abs(hourOffset)); } else { if (hourOffset < 10) { sb.append("+0"); } else { sb.append("+"); } sb.append(hourOffset); } sb.append(':'); if (minuteOffset == 0) { sb.append("00"); } else if (minuteOffset < 10) { sb.append('0').append(minuteOffset); } else { sb.append(minuteOffset); } return sb.toString(); }
From source file:com.redhat.rhn.frontend.xmlrpc.system.SystemHandler.java
private Date convertLocalToUtc(Date in) { Calendar c = Calendar.getInstance(); c.setTime(in);/*from w w w . j a v a 2 s . c om*/ TimeZone z = c.getTimeZone(); int offset = z.getRawOffset(); if (z.inDaylightTime(in)) { offset += z.getDSTSavings(); } int offsetHrs = offset / 1000 / 60 / 60; int offsetMins = offset / 1000 / 60 % 60; c.add(Calendar.HOUR_OF_DAY, (-offsetHrs)); c.add(Calendar.MINUTE, (-offsetMins)); c.set(Calendar.MILLISECOND, 0); return c.getTime(); }