Class DateConverter


  • public class DateConverter
    extends java.lang.Object
    The DateConverter is a helper class that provides methods for handling the all kind of date formats.
    E.g. the ISO8601 date format (A short summary about the ISO8601 date format can be accessed at the W3C.), or the Julian date.
    Since:
    1.0
    Author:
    doergn@users.sourceforge.net
    • Constructor Summary

      Constructors 
      Constructor Description
      DateConverter()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      private static java.util.TimeZone createTimezone​(java.lang.String timeZone)  
      private static java.lang.String cutLeadingZeroAndPlus​(java.lang.String value)  
      private static java.lang.String formatTimezone​(int min)  
      static java.lang.String setLeadingZero​(double value)  
      static java.lang.String setLeadingZero​(int value)  
      static java.util.Calendar toDate​(java.lang.String iso8601)
      Converts a String object that contains a ISO8601 conform value to an java.util.Calendar object.
      static java.util.Calendar toGregorianDate​(double julianDate)
      Converts a julian date into a gregorian date.
      static java.util.Calendar toGregorianDate​(double julianDate, java.util.TimeZone zone)
      Converts a julian date into a gregorian date.
      static java.lang.String toISO8601​(java.util.Calendar calendar)
      Converts a Date object into a String object that represents a ISO8601 conform string.
      static double toJulianDate​(java.util.Calendar gregorianCalendar)
      Converts a gregorian date into a julian date.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • toJulianDate

        public static double toJulianDate​(java.util.Calendar gregorianCalendar)
        Converts a gregorian date into a julian date.
        Parameters:
        gregorianDate - The gregorianDate date
        Returns:
        A julian date with seconds accuracy
      • toGregorianDate

        public static java.util.Calendar toGregorianDate​(double julianDate)
        Converts a julian date into a gregorian date.
        Parameters:
        julianDate - The julian date
        Returns:
        A gregorian date with seconds accuracy (Timezone = GMT)
      • toGregorianDate

        public static java.util.Calendar toGregorianDate​(double julianDate,
                                                         java.util.TimeZone zone)
        Converts a julian date into a gregorian date.
        Parameters:
        julianDate - The julian date
        zone - The timzone for the returned gregorian date (if NULL is passed GMT will be taken)
        Returns:
        A gregorian date
      • toISO8601

        public static java.lang.String toISO8601​(java.util.Calendar calendar)
        Converts a Date object into a String object that represents a ISO8601 conform string.
        Parameters:
        calendar - A java.util.Date object that has to be converted
        Returns:
        A ISO8601 conform String, or null if the given date was null
      • toDate

        public static java.util.Calendar toDate​(java.lang.String iso8601)
                                         throws java.lang.NumberFormatException
        Converts a String object that contains a ISO8601 conform value to an java.util.Calendar object.
        Parameters:
        iso8601 - A String with a ISO8601 conform value
        Returns:
        The parameters date as java.util.Calendar, or null if the given string was null or empty.
        Throws:
        java.lang.NumberFormatException - if given ISO8601 is malformed.
      • createTimezone

        private static java.util.TimeZone createTimezone​(java.lang.String timeZone)
                                                  throws java.lang.NumberFormatException
        Throws:
        java.lang.NumberFormatException
      • setLeadingZero

        public static java.lang.String setLeadingZero​(int value)
      • setLeadingZero

        public static java.lang.String setLeadingZero​(double value)
      • cutLeadingZeroAndPlus

        private static java.lang.String cutLeadingZeroAndPlus​(java.lang.String value)
      • formatTimezone

        private static java.lang.String formatTimezone​(int min)