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:Main.java

public static void main(String args[]) {

    TimeZone timezone = TimeZone.getDefault();

    // checking raw offset value     
    System.out.println("Raw Offset value:" + timezone.getRawOffset());
}

From source file:Main.java

public static void main(String args[]) {

    TimeZone tzone = TimeZone.getDefault();

    // set raw offset
    tzone.setRawOffset(10000);//from  w  w  w.  ja  v  a 2  s . c om

    // checking offset value
    System.out.println("Offset value is :" + tzone.getRawOffset());
}

From source file:KVMTimeZones.java

public static void main(String[] args) {
    TimeZone defaultTZ = TimeZone.getDefault();
    String[] ids = TimeZone.getAvailableIDs();

    System.out.println("Available time zone ids: ");
    for (int i = 0; i < ids.length; i++) {
        System.out.print(ids[i] + " ");
    }//from  ww w.  j ava2 s  . com
    System.out.println(
            "\nDefault timezone is " + defaultTZ.getID() + ", GMT offset = " + defaultTZ.getRawOffset());
}

From source file:Main.java

/**
 * //from www  .j  av  a 2  s  . c  o  m
 * @return
 */
public static long getMillisGMT() {
    Calendar calendar = new GregorianCalendar();
    TimeZone mTimeZone = calendar.getTimeZone();
    int offset = mTimeZone.getRawOffset();
    return System.currentTimeMillis() - offset;
}

From source file:Main.java

public static String getTimeZoneOffset() {
    TimeZone timezone = TimeZone.getDefault();
    int i = timezone.getRawOffset() / 1000;
    int j;//from   ww  w  . j  a  v a  2s  . c  o m
    double d;
    Object aobj[];
    if (timezone.useDaylightTime() && timezone.inDaylightTime(new java.sql.Date(System.currentTimeMillis())))
        j = 1;
    else
        j = 0;
    d = (double) i / 3600D + (double) j;
    aobj = new Object[1];
    aobj[0] = Double.valueOf(d);
    return String.format("%.2f", aobj);
}

From source file:Main.java

/**
 * Returns a formatted string representation of time in <code>milliseconds</code>
 * @param milliseconds Long value representing the time to be formatted
 * @return Formatted string representation of time in <code>milliseconds</code>
 *//*from  w ww .j a  v  a 2s. com*/
public static String getOfxFormattedTime(long milliseconds) {
    Date date = new Date(milliseconds);
    String dateString = OFX_DATE_FORMATTER.format(date);
    TimeZone tz = Calendar.getInstance().getTimeZone();
    int offset = tz.getRawOffset();
    int hours = (int) ((offset / (1000 * 60 * 60)) % 24);
    String sign = offset > 0 ? "+" : "";
    return dateString + "[" + sign + hours + ":" + tz.getDisplayName(false, TimeZone.SHORT, Locale.getDefault())
            + "]";
}

From source file:Main.java

/**
 * Returns Timezone Offset From UTC in format {@code (+|i)HHMM} of specified
 * Timezone without concerning Daylight saving time (DST).
 *
 * @param tz Timezone/*from  ww w  .  jav a 2s .c o m*/
 * @return Timezone Offset From UTC in format {@code (+|i)HHMM}
 */
public static String formatTimezoneOffsetFromUTC(TimeZone tz) {
    return appendZZZZZ(tz.getRawOffset(), new StringBuilder(5)).toString();
}

From source file:Main.java

/**
 * Produce a string describing the offset of the given time zone from
 * UTC, including the DST offset if there is one.
 * /*w w w. java 2s. c  o  m*/
 * @param   zone         TimeZone whose offset we want.
 * @return               Formatted offset.
 */
public static String formatOffset(TimeZone zone) {
    String fmt = "";

    int base = zone.getRawOffset();
    fmt += "UTC" + intervalMsToHmsShort(base);

    int dst = zone.getDSTSavings();
    if (dst != 0)
        fmt += " (UTC" + intervalMsToHmsShort(base + dst) + ")";

    return fmt;
}

From source file:Main.java

/**
 * Produce a string describing the offset of the given time zone from
 * UTC, including the DST offset if there is one.
 * //from   ww  w  . jav  a  2s  .  c om
 * @param   zone         TimeZone whose offset we want.
 * @return               Formatted offset.
 */
public static String formatOffsetFull(TimeZone zone) {
    String fmt = zone.getID() + ": ";

    int base = zone.getRawOffset();
    fmt += zone.getDisplayName(false, TimeZone.LONG) + "=UTC" + intervalMsToHmsShort(base);

    int dst = zone.getDSTSavings();
    if (dst != 0)
        fmt += " (" + zone.getDisplayName(true, TimeZone.LONG) + "=UTC" + intervalMsToHmsShort(base + dst)
                + ")";

    return fmt;
}

From source file:org.forgerock.openam.cts.TokenTestUtils.java

/**
 * Required to correctly account for all factors when dealing with TimeZones.
 *
 * @param zone Non null./*w  ww. j  a v  a 2s.com*/
 * @return
 */
private static int getTotalTimeZoneOffset(TimeZone zone) {
    int r = zone.getRawOffset();
    if (zone.useDaylightTime()) {
        r += zone.getDSTSavings();
    }
    return r;
}