Example usage for java.util TimeZone getID

List of usage examples for java.util TimeZone getID

Introduction

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

Prototype

public String getID() 

Source Link

Document

Gets the ID of this time zone.

Usage

From source file:Main.java

public static void main(String args[]) {

    TimeZone timezone = TimeZone.getTimeZone("Europe/Paris");

    // checking ID of this time zone         
    System.out.println("ID value is :" + timezone.getID());
}

From source file:Main.java

public static void main(String args[]) {

    TimeZone tzone = TimeZone.getDefault();

    // set time zone ID
    tzone.setID("GMT+08:00");

    // checking time zone ID
    System.out.println("Time zone ID:" + tzone.getID());
}

From source file:Main.java

public static void main(String[] args) {
    GregorianCalendar gc = new GregorianCalendar(2014, 1, 11, 15, 45, 50);
    LocalDate ld = gc.toZonedDateTime().toLocalDate();
    System.out.println("Local  Date: " + ld);

    LocalTime lt = gc.toZonedDateTime().toLocalTime();
    System.out.println("Local Time:  " + lt);

    LocalDateTime ldt = gc.toZonedDateTime().toLocalDateTime();
    System.out.println("Local DateTime:  " + ldt);

    OffsetDateTime od = gc.toZonedDateTime().toOffsetDateTime();
    System.out.println("Offset  Date: " + od);

    OffsetTime ot = gc.toZonedDateTime().toOffsetDateTime().toOffsetTime();
    System.out.println("Offset Time:  " + ot);

    ZonedDateTime zdt = gc.toZonedDateTime();
    System.out.println("Zoned DateTime:  " + zdt);

    ZoneId zoneId = zdt.getZone();
    TimeZone timeZone = TimeZone.getTimeZone(zoneId);
    System.out.println("Zone ID:  " + zoneId);
    System.out.println("Time Zone ID:  " + timeZone.getID());

    GregorianCalendar gc2 = GregorianCalendar.from(zdt);
    System.out.println("Gregorian  Calendar: " + gc2.getTime());
}

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] + " ");
    }//  w w  w . jav  a 2s  . c om
    System.out.println(
            "\nDefault timezone is " + defaultTZ.getID() + ", GMT offset = " + defaultTZ.getRawOffset());
}

From source file:Main.java

public static String timeZoneToString(TimeZone tz) {

    return tz != null ? tz.getID() : "";
}

From source file:Main.java

public static String getDeviceTimeZone() {
    Calendar calendar = Calendar.getInstance();
    TimeZone timeZone = calendar.getTimeZone();
    String retString = timeZone.getTimeZone(timeZone.getID()).getID();
    return retString;
}

From source file:Main.java

public static String getUserPhoneTimezone() {
    TimeZone timeZone = TimeZone.getDefault();

    timeZone = timeZone.getTimeZone(timeZone.getID());
    Date date = new Date();

    DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    df.setTimeZone(timeZone);// w w  w  .  j a va 2s  .  c  om

    return df.format(date);
}

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 2  s.co  m*/
 * @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:Main.java

private static TimeZone safeTimeZone(String s) {
    String tzid = tzid(s);//  w w  w.j  ava  2s.  co  m
    if (tzid == null)
        return null;

    TimeZone tz = cachedTimeZone;
    if (tz == null || !tz.getID().equals(tzid))
        cachedTimeZone = tz = TimeZone.getTimeZone(tzid);

    return tz;
}

From source file:Main.java

/**
 * @NAME getSimpleTZTag<br>/*from   www .ja va  2  s.co m*/
 *   getSimpleTZTag
 */
public static String getSimpleTZTag() {
    try {
        TimeZone tz = TimeZone.getDefault();
        String s = "tz." + tz.getDisplayName(false, TimeZone.SHORT) + "tzid." + tz.getID();

        return s;
    } catch (Exception e) {
        return "";
    }
}