Java TimeZone Usage createPostgresTimeZone()

Here you can find the source of createPostgresTimeZone()

Description

Convert Java time zone to postgres time zone.

License

Open Source License

Return

The current JVM time zone in postgresql format.

Declaration

public static String createPostgresTimeZone() 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.TimeZone;

public class Main {
    /**//from  w w w . j ava 2s  .c  om
     * Convert Java time zone to postgres time zone. All others stay the same
     * except that GMT+nn changes to GMT-nn and vise versa.
     * 
     * @return The current JVM time zone in postgresql format.
     */
    public static String createPostgresTimeZone() {
        String tz = TimeZone.getDefault().getID();
        if (tz.length() <= 3 || !tz.startsWith("GMT")) {
            return tz;
        }
        char sign = tz.charAt(3);
        String start;
        if (sign == '+') {
            start = "GMT-";
        } else if (sign == '-') {
            start = "GMT+";
        } else {
            // unknown type
            return tz;
        }
        return start + tz.substring(4);
    }
}

Related

  1. addGmtOffset(long millis)
  2. assertTimeZoneNotNull(String methodName, TimeZone timeZone)
  3. buildTimezone(int hours, int minutes)
  4. computeTimeZoneOffsetInHours(TimeZone timeZone, long currentDatetime)
  5. createTaiTimeZone(int leapSecs)
  6. datePlusDays(Date date, int days)
  7. findTimeZoneInDate(String date)
  8. isInEasternEightZones()