Example usage for java.util TimeZone getRawOffset

List of usage examples for java.util TimeZone getRawOffset

Introduction

In this page you can find the example usage for java.util TimeZone getRawOffset.

Prototype

public abstract int getRawOffset();

Source Link

Document

Returns the amount of time in milliseconds to add to UTC to get standard time in this time zone.

Usage

From source file:com.onesignal.OneSignal.java

private static int getTimeZoneOffset() {
    TimeZone timezone = Calendar.getInstance().getTimeZone();
    int offset = timezone.getRawOffset();

    if (timezone.inDaylightTime(new Date()))
        offset = offset + timezone.getDSTSavings();

    return offset / 1000;
}

From source file:fr.certu.chouette.validation.checkpoint.AbstractValidation.java

protected long getTimeInSeconds(Time time) {
    TimeZone tz = TimeZone.getDefault();
    long millis = 0;
    millis = time.getTime() + tz.getRawOffset();
    return millis / 1000;
}

From source file:org.kalypso.model.hydrology.operation.evaporation.AbstractEvaporationCalculator.java

private LocalTime getTimeStamp() {
    final TimeZone timeZone = KalypsoCorePlugin.getDefault().getTimeZone();

    final int rawOffset = timeZone.getRawOffset();

    final Calendar calendar = CalendarUtilities.getCalendar(getDateRange().getFrom(), timeZone);
    calendar.set(Calendar.HOUR_OF_DAY, 12);
    calendar.set(Calendar.MINUTE, 0);
    calendar.set(Calendar.SECOND, 0);
    calendar.set(Calendar.MILLISECOND, 0);

    calendar.add(Calendar.MILLISECOND, -rawOffset);

    /* REMARK: The ISO Chronolgy used will have the UTC timezone set. */

    /* We set the timestamp so, that in the local time, it is always 12:00 */

    return new LocalTime(calendar.get(Calendar.HOUR_OF_DAY), calendar.get(Calendar.MINUTE));
}

From source file:MonitoredGregorianCalendar.java

public void setTimeZone(TimeZone zone) {
    if (!blocked) {
        blocked = true;//  w w  w  .ja  v a  2s  . c om
        super.setTimeZone(zone);
        blocked = false;
        changed(CalendarChangeListener.TYPE_SET, CalendarChangeListener.TIME_ZONE, zone.getRawOffset());
    } else {
        super.setTimeZone(zone);
    }
}

From source file:com.microsoft.exchange.DateHelpTest.java

@Test
public void systemTimeZone() {
    List<String> availableIDs = Arrays.asList(TimeZone.getAvailableIDs());
    assertFalse(CollectionUtils.isEmpty(availableIDs));
    assertTrue(availableIDs.contains(TimeZones.UTC_ID));
    assertTrue(availableIDs.contains("UTC"));

    TimeZone ical4jUTC = TimeZone.getTimeZone(TimeZones.UTC_ID);
    TimeZone sysUTC = TimeZone.getTimeZone("UTC");

    assertEquals(ical4jUTC.getDSTSavings(), sysUTC.getDSTSavings());
    assertEquals(ical4jUTC.getRawOffset(), sysUTC.getRawOffset());
    assertTrue(ical4jUTC.hasSameRules(sysUTC));

    TimeZone origDefaultTimeZone = TimeZone.getDefault();
    assertNotNull(origDefaultTimeZone);/*from   w ww .j  av  a 2s.com*/
    assertEquals(TimeZone.getDefault().getRawOffset(), origDefaultTimeZone.getRawOffset());

    log.info("TimeZone.DisplayName=" + origDefaultTimeZone.getDisplayName());
    log.info("TimeZone.ID=" + origDefaultTimeZone.getID());
    log.info("TimeZone.DSTSavings=" + origDefaultTimeZone.getDSTSavings());
    log.info("TimeZone.RawOffset=" + origDefaultTimeZone.getRawOffset());
    log.info("TimeZone.useDaylightTime=" + origDefaultTimeZone.useDaylightTime());

    TimeZone.setDefault(ical4jUTC);
    assertEquals(ical4jUTC, TimeZone.getDefault());
    log.info(" -- Defualt Time Zone has been changed successfully! -- ");

    TimeZone newDefaultTimeZone = TimeZone.getDefault();
    log.info("TimeZone.DisplayName=" + newDefaultTimeZone.getDisplayName());
    log.info("TimeZone.ID=" + newDefaultTimeZone.getID());
    log.info("TimeZone.DSTSavings=" + newDefaultTimeZone.getDSTSavings());
    log.info("TimeZone.RawOffset=" + newDefaultTimeZone.getRawOffset());
    log.info("TimeZone.useDaylightTime=" + newDefaultTimeZone.useDaylightTime());
}

From source file:com.microsoft.exchange.DateHelpTest.java

/**
 * Computes the time zone offset for a given {@link XMLGregorianCalendar} and compares to the specified {@link TimeZone}
 * /*from   www. ja v  a  2  s  .c o m*/
 * 
 * 
 * @param xmlGregorianCalendar
 * @param timeZone
 */
public boolean xmlGregorianCalendareMatchesTimeZone(XMLGregorianCalendar xmlGregorianCalendar,
        TimeZone timeZone) {
    int xmlTimeZoneOffsetMinutes = xmlGregorianCalendar.getTimezone();
    TimeZone xmlTimeZone = xmlGregorianCalendar.getTimeZone(xmlTimeZoneOffsetMinutes);
    int jvmRawOffsetMinutes = (timeZone.getRawOffset() / 1000 / 60);
    int jvmDstOffsetMinutes = (timeZone.getDSTSavings() / 1000 / 60);

    int xmlRawOffsetMinutes = (xmlTimeZone.getRawOffset() / 1000 / 60);
    int xmlDstOffsetMinutes = (xmlTimeZone.getDSTSavings() / 1000 / 60);

    //XMLGregorianCalendar only stores an Int for offset, no DST information.  
    //as a result the xmlTimeZone and jvmTimeZone almost never follow the same rules
    if (timeZone.hasSameRules(xmlTimeZone)) {
        log.debug("xmlTimeZoneId=" + xmlTimeZone.getID() + " hasSameRules as jvmTimeZone=" + timeZone.getID());
        return true;
    }

    if (timeZone.useDaylightTime()) {
        //they definately do not when the jvmTimeZone uses DST.
        assertFalse(xmlTimeZone.hasSameRules(timeZone));
        jvmRawOffsetMinutes += jvmDstOffsetMinutes;
    }

    if (xmlTimeZone.useDaylightTime()) {
        xmlRawOffsetMinutes += xmlDstOffsetMinutes;
    }
    if (xmlTimeZoneOffsetMinutes != xmlRawOffsetMinutes) {
        log.info("xmlTimeZoneId=" + xmlTimeZone.getID() + " has weird rules");
    }

    return (jvmRawOffsetMinutes == xmlRawOffsetMinutes);

}

From source file:jef.tools.DateUtils.java

/**
 * ?????//from  w ww .  ja va  2 s  .  c  om
 * 
 * @param d
 * @param unit
 *            ??
 * @param zone
 *            ?? ???
 * @return
 */
public static boolean isOnTime(Date d, TimeUnit unit, TimeZone zone) {
    BigInteger i = BigInteger.valueOf(d.getTime() + zone.getRawOffset());
    long result = i.mod(BigInteger.valueOf(unit.ms)).longValue();
    return result == 0;
}

From source file:com.mirth.connect.client.ui.StatusBar.java

private String convertLocalToServerTime() {
    TimeZone localTimeZone = TimeZone.getTimeZone(this.localTimeZone);
    TimeZone serverTimeZone = TimeZone.getTimeZone(this.serverTimeZone);

    Calendar calendar = Calendar.getInstance();
    calendar.add(Calendar.MILLISECOND, (int) timeOffset);

    calendar.add(Calendar.MILLISECOND, localTimeZone.getRawOffset() * -1);
    if (localTimeZone.inDaylightTime(calendar.getTime())) {
        calendar.add(Calendar.MILLISECOND, localTimeZone.getDSTSavings() * -1);
    }//from  www  .  j  a  v  a  2s .c  o m

    calendar.add(Calendar.MILLISECOND, serverTimeZone.getRawOffset());
    if (serverTimeZone.inDaylightTime(calendar.getTime())) {
        calendar.add(Calendar.MILLISECOND, serverTimeZone.getDSTSavings());
    }

    return new SimpleDateFormat("h:mm a").format(calendar.getTime());
}

From source file:com.cubusmail.gwtui.server.services.UserAccountService.java

public String[][] retrieveTimezones() {

    NumberFormat format = new DecimalFormat("00");
    Locale locale = SessionManager.get().getLocale();
    ResourceBundle bundle = ConvertUtil.getTimezonesBundle(locale);
    Enumeration<String> ids = bundle.getKeys();
    List<TimeZone> timeZoneList = toSortedZimeZoneList(ids);
    String[][] result = new String[timeZoneList.size()][2];
    int index = 0;
    for (TimeZone timeZone : timeZoneList) {
        result[index][0] = timeZone.getID();
        String hours = format.format(timeZone.getRawOffset() / 3600000);
        if (timeZone.getRawOffset() >= 0) {
            result[index][1] = "(+" + hours + ":00) " + bundle.getString(timeZone.getID());
        } else {//from w w w . jav a2 s  .  com
            result[index][1] = "(" + hours + ":00) " + bundle.getString(timeZone.getID());
        }
        index++;
    }

    return result;
}

From source file:Panels.LocationPanel.java

public boolean getLocationFromIP() {
    boolean b = false;
    try {/*from w w  w .j av  a2s.  c  om*/
        URL whatismyip = new URL("http://checkip.amazonaws.com");
        BufferedReader in = new BufferedReader(new InputStreamReader(whatismyip.openStream()));
        String ip = in.readLine();

        URL url = new URL("http://freegeoip.net/json/" + ip);
        BufferedReader inn = new BufferedReader(new InputStreamReader(url.openStream()));
        String s = inn.readLine();

        JSONParser jsonParser = new JSONParser();
        JSONObject jsonObject = (JSONObject) jsonParser.parse(s);

        country = jsonObject.get("country_name").toString();
        city = jsonObject.get("city").toString();
        longitude = jsonObject.get("longitude").toString();
        latitude = jsonObject.get("latitude").toString();

        TimeZone tz = TimeZone.getTimeZone((String) jsonObject.get("time_zone"));

        timezone = String.valueOf(((tz.getRawOffset()) / (60 * 60 * 1000D)));

        if (!country.equalsIgnoreCase("") && !city.equalsIgnoreCase("") && !longitude.equalsIgnoreCase("")
                && !latitude.equalsIgnoreCase("") && !timezone.equalsIgnoreCase("")) {
            b = true;
        }
    } catch (Exception e) {
        b = false;
        this.locationFromInternet.setEnabled(true);
        this.locationFromInternet.setIcon(locationfromInternetIcon);
    }
    return b;
}