Class TimeZoneTool


  • public class TimeZoneTool
    extends java.lang.Object
    Time zone tools
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String FORMAT_ISO
      Format of ISO time (T ending with +hh:mm)
      static java.lang.String FORMAT_LOCAL
      Format of local server time (without T and zone)
      static java.lang.String FORMAT_UTC
      Format of UTC time (T ending with Z)
    • Constructor Summary

      Constructors 
      Constructor Description
      TimeZoneTool()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String convertDateUTC2Local​(java.lang.String date)
      Convert a UTC date to local date
      static java.lang.String convertLocalDate2TimeZone​(java.lang.String date, java.lang.String zoneID)
      Convert the internal date format to timezone (ISO-8601)
      static java.lang.String convertLocalDate2TimeZone​(java.lang.String date, java.util.TimeZone zone)
      Convert the internal date format to timezone (ISO-8601)
      static java.lang.String convertTimeZone​(java.lang.String date, java.util.TimeZone fromTZ, java.util.TimeZone toTZ, java.lang.String format)
      Convert a date
      static java.lang.String convertTimeZone2LocalDate​(java.lang.String date)
      Convert the timezone (ISO-8601) to internal date format
      static java.lang.String convertTimeZone2LocalDate​(java.lang.String date, java.lang.String zoneID)
      Convert the date to internal date format
      static java.lang.String convertTimeZone2LocalDate​(java.lang.String date, java.util.TimeZone zone)
      Convert the date to internal date format
      static java.lang.String formatDate2TimeZone​(java.lang.String date)
      Format the internal date format to ISO-8601
      static java.text.SimpleDateFormat getDateFormat​(java.lang.String date)
      Determine date format for a date
      static java.lang.String getTimeZoneOffset​(java.util.TimeZone tz, boolean daylight)
      Time zone offset as text
      static java.util.List<java.util.TimeZone> list()
      List all time zones
      static void main​(java.lang.String[] args)  
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • FORMAT_LOCAL

        public static final java.lang.String FORMAT_LOCAL
        Format of local server time (without T and zone)
        See Also:
        Constant Field Values
      • FORMAT_UTC

        public static final java.lang.String FORMAT_UTC
        Format of UTC time (T ending with Z)
        See Also:
        Constant Field Values
      • FORMAT_ISO

        public static final java.lang.String FORMAT_ISO
        Format of ISO time (T ending with +hh:mm)
        See Also:
        Constant Field Values
    • Constructor Detail

      • TimeZoneTool

        public TimeZoneTool()
    • Method Detail

      • getDateFormat

        public static java.text.SimpleDateFormat getDateFormat​(java.lang.String date)
        Determine date format for a date
        Parameters:
        date - local or ISO
        Returns:
        date formatter
      • list

        public static java.util.List<java.util.TimeZone> list()
        List all time zones
      • getTimeZoneOffset

        public static java.lang.String getTimeZoneOffset​(java.util.TimeZone tz,
                                                         boolean daylight)
        Time zone offset as text
        Parameters:
        tz - Time zone
        daylight - true to include the current daylight time (or summer time in Europe)
        Returns:
        "Z" for UTC time or "+hh:mm" (ISO-8601)
      • convertTimeZone

        public static java.lang.String convertTimeZone​(java.lang.String date,
                                                       java.util.TimeZone fromTZ,
                                                       java.util.TimeZone toTZ,
                                                       java.lang.String format)
        Convert a date
        Parameters:
        date - YYYY-MM-DD HH:MM:SS or ISO format
        fromTZ - From timezone (ex TimeZone.getTimeZone("UTC"))
        toTZ - To timezone (ex TimeZone.getDefault() for local time zone)
        format - output format (FORMAT_ISO by default)
        Returns:
        time translated in the target timezone
      • convertDateUTC2Local

        public static java.lang.String convertDateUTC2Local​(java.lang.String date)
        Convert a UTC date to local date
        Parameters:
        date - YYYY-MM-DD HH:MM:SS
        Returns:
        YYYY-MM-DD HH:MM:SS in local timezone
      • formatDate2TimeZone

        public static java.lang.String formatDate2TimeZone​(java.lang.String date)
        Format the internal date format to ISO-8601
        Parameters:
        date - YYYY-MM-DD HH:MM:SS (local timezone of DB)
        Returns:
        YYYY-MM-DDTHH:MM:SSZ or YYYY-MM-DDTHH:MM:SS+hh:mm
      • convertLocalDate2TimeZone

        public static java.lang.String convertLocalDate2TimeZone​(java.lang.String date,
                                                                 java.lang.String zoneID)
        Convert the internal date format to timezone (ISO-8601)
        Parameters:
        date - YYYY-MM-DD HH:MM:SS
        zoneID - Time zone ID
        Returns:
        YYYY-MM-DDTHH:MM:SS+hh:mm
      • convertLocalDate2TimeZone

        public static java.lang.String convertLocalDate2TimeZone​(java.lang.String date,
                                                                 java.util.TimeZone zone)
        Convert the internal date format to timezone (ISO-8601)
        Parameters:
        date - YYYY-MM-DD HH:MM:SS
        zone - Target time zone
        Returns:
        YYYY-MM-DDTHH:MM:SS+hh:mm
      • convertTimeZone2LocalDate

        public static java.lang.String convertTimeZone2LocalDate​(java.lang.String date)
        Convert the timezone (ISO-8601) to internal date format
        Parameters:
        date - YYYY-MM-DDTHH:MM:SS+hh:mm or Z
        Returns:
        YYYY-MM-DD HH:MM:SS in local server time
      • convertTimeZone2LocalDate

        public static java.lang.String convertTimeZone2LocalDate​(java.lang.String date,
                                                                 java.lang.String zoneID)
        Convert the date to internal date format
        Parameters:
        date - YYYY-MM-DD HH:MM:SS
        zoneID - Date time zone ID
        Returns:
        YYYY-MM-DD HH:MM:SS in local server time
      • convertTimeZone2LocalDate

        public static java.lang.String convertTimeZone2LocalDate​(java.lang.String date,
                                                                 java.util.TimeZone zone)
        Convert the date to internal date format
        Parameters:
        date - YYYY-MM-DD HH:MM:SS
        zone - Date time zone
        Returns:
        YYYY-MM-DD HH:MM:SS in local server time
      • main

        public static void main​(java.lang.String[] args)