Difference between revisions of "DateUtils"

From GreenVulcano Wiki
Jump to: navigation, search
(Created page with "Class FQN: '''it.greenvulcano.util.txt''' ==Following the DateUtils public static methods== * Parsing <syntaxhighlight lang="java5"> DateUtils public static Locale getDefa...")
 
 
(13 intermediate revisions by 3 users not shown)
Line 1: Line 1:
Class FQN: '''it.greenvulcano.util.txt'''
+
Class FQN: '''it.greenvulcano.util.txt.DateUtils'''
  
==Following the DateUtils public static methods==
+
==Following the DateUtils public constants==
* Parsing
+
<syntaxhighlight lang="java5">
<syntaxhighlight lang="java5">  
+
     /**
DateUtils
+
    * The conversion pattern to be used for input string that represent an OS timestamp.
 
+
    */
     public static Locale getDefaultLocale()
+
     String FORMAT_SYSTEM_TIME      = "SYSTEM_TIME";
    {
 
        return locale;
 
     }
 
 
 
    public static TimeZone getDefaultTimeZone()
 
    {
 
        return timeZone;
 
    }
 
  
 
     /**
 
     /**
     * Create a Calendar instance with default timezone.
+
     * Short ISO date/time format
     *  
+
    */
     * @return
+
    String FORMAT_ISO_DATE_S        = "yyyyMMdd";
 +
    String FORMAT_ISO_TIME_S        = "HHmmss";
 +
    String FORMAT_ISO_DATETIME_S    = "yyyyMMdd HHmmss";
 +
    String FORMAT_ISO_TIMESTAMP_S  = "yyyyMMdd HHmmssSSS";
 +
    /**
 +
    * Long ISO date/time format
 +
    */
 +
    String FORMAT_ISO_DATE_L        = "yyyy-MM-dd";
 +
    String FORMAT_ISO_TIME_L        = "HH:mm:ss";
 +
    String FORMAT_ISO_DATETIME_L    = "yyyy-MM-dd HH:mm:ss";
 +
    String FORMAT_ISO_TIMESTAMP_L  = "yyyy-MM-dd HH:mm:ss.SSS";
 +
    /**
 +
     * ISO date/time + UTC format
 +
    */
 +
    String FORMAT_ISO_DATETIME_UTC  = "yyyy-MM-dd'T'HH:mm:ssZ";
 +
    /**
 +
     * IETF date/time format
 
     */
 
     */
     public static Calendar createCalendar()
+
     String FORMAT_IETF_DATETIME    = "EEE, d MMM yyyy HH:mm:ss z";
 +
 
 +
    String DEFAULT_FORMAT_DATE      = FORMAT_ISO_DATE_L;
 +
    String DEFAULT_FORMAT_TIME      = FORMAT_ISO_TIME_L;
 +
    String DEFAULT_FORMAT_DATETIME  = FORMAT_ISO_DATETIME_L;
 +
    String DEFAULT_FORMAT_TIMESTAMP = FORMAT_ISO_TIMESTAMP_L;
 +
</syntaxhighlight>
  
 +
==Following the DateUtils public static methods==
 +
* Date/Time conversion
 +
<syntaxhighlight lang="java5">
 
     /**
 
     /**
     * Convert a {@link java.lang.String} representation to a
+
     * Convert a String date representation to a Date instance.
    * {@link java.util.Date} instance.
 
 
     *  
 
     *  
     * @param date
+
     * @param date  
     *       the string representation of Date/Time
+
     *             the string representation of Date/Time
     * @param format
+
     * @param format  
     *       the conversion pattern
+
     *             the conversion pattern
 
     * @return a Date instance
 
     * @return a Date instance
 
     */
 
     */
Line 36: Line 52:
  
 
     /**
 
     /**
     * Convert a {@link java.lang.String} representation to a
+
     * Convert a String date representation to a Date instance.
    * {@link java.util.Date} instance.
 
 
     *  
 
     *  
     * @param date the string representation of Date/Time
+
     * @param date  
     * @param format the conversion pattern
+
    *            the string representation of Date/Time
     * @param tZone the TimeZone
+
     * @param format  
 +
    *            the conversion pattern
 +
     * @param tZone  
 +
    *            the TimeZone to be used in conversion
 
     * @return a Date instance
 
     * @return a Date instance
 
     */
 
     */
Line 47: Line 65:
  
 
     /**
 
     /**
     * Convert a {@link java.lang.String} representation to a
+
     * Convert a String date representation to a Date instance.
    * {@link java.util.Date} instance.
 
 
     *  
 
     *  
     * @param date the string representation of Date/Time
+
     * @param date  
     * @param format the conversion pattern
+
    *            the string representation of Date/Time
     * @param tZone the TimeZone
+
     * @param format  
     * @param lang the locale to be used in conversion
+
    *            the conversion pattern
 +
     * @param tZone  
 +
    *            the TimeZone to be used in conversion
 +
     * @param lang  
 +
    *            the Locale to be used in conversion
 
     * @return a Date instance
 
     * @return a Date instance
 
     */
 
     */
 
     public static Date stringToDate(String date, String format, String tZone, String lang)
 
     public static Date stringToDate(String date, String format, String tZone, String lang)
 
  
 
     /**
 
     /**
     * Convert a {@link java.util.Date} instance to a {@link java.lang.String}
+
     * Convert a Date instance to a String representation.
    * representation.
 
 
     *  
 
     *  
     * @param date the Date instance to convert
+
     * @param date  
     * @param format the conversion pattern
+
    *            the Date instance to convert
     * @return a string representation of date
+
     * @param format  
 +
    *            the conversion pattern
 +
     * @return a String representation of date
 
     */
 
     */
 
     public static String dateToString(Date date, String format)
 
     public static String dateToString(Date date, String format)
  
 
     /**
 
     /**
     * Convert a {@link java.util.Date} instance to a {@link java.lang.String}
+
     * Convert a Date instance to a String representation.
    * representation.
 
 
     *  
 
     *  
     * @param date the Date instance to convert
+
     * @param date  
     * @param format the conversion pattern
+
    *            the Date instance to convert
     * @param tZone the TimeZone
+
     * @param format  
     * @return a string representation of date
+
    *            the conversion pattern
 +
     * @param tZone  
 +
    *            the TimeZone to be used in conversion
 +
     * @return a String representation of date
 
     */
 
     */
 
     public static String dateToString(Date date, String format, String tZone)
 
     public static String dateToString(Date date, String format, String tZone)
  
 
     /**
 
     /**
     * Convert a {@link java.util.Date} instance to a {@link java.lang.String}
+
     * Convert a Date instance to a String representation.
    * representation.
 
 
     *  
 
     *  
     * @param date
+
     * @param date  
     *       the Date instance to convert
+
     *             the Date instance to convert
     * @param format
+
     * @param format  
     *       the conversion pattern
+
     *             the conversion pattern
     * @param tZone
+
     * @param tZone  
     *       the TimeZone
+
     *             the TimeZone to be used in conversion
     * @param lang
+
     * @param lang  
     *       the locale to be used in conversion
+
     *             the Locale to be used in conversion
     * @return a string representation of date
+
     * @return a String representation of date
 
     */
 
     */
 
     public static String dateToString(Date date, String format, String tZone, String lang)
 
     public static String dateToString(Date date, String format, String tZone, String lang)
 
 
  
 
     /**
 
     /**
     * Convert a {@link java.lang.String} representation of date/Time to another
+
     * Convert a String representation of date/Time to another format.
     * format. The output string representation is formatted according to
+
     * The string representation is interpreted according to
     * <b>local</b> timezone.
+
     * default locale/timezone.
 
     *  
 
     *  
     * @param date the date/time representation to convert
+
     * @param date  
     * @param formatIn the input date/time conversion pattern
+
    *            the date/time representation to convert
     * @param formatOut the output date/time conversion pattern
+
     * @param formatIn  
     * @return the new string representation
+
    *            the input date/time conversion pattern
 +
     * @param formatOut  
 +
    *            the output date/time conversion pattern
 +
     * @return the new String representation
 
     */
 
     */
 
     public static String convertString(String date, String formatIn, String formatOut)
 
     public static String convertString(String date, String formatIn, String formatOut)
 
  
 
     /**
 
     /**
     * Convert a {@link java.lang.String} representation of date/Time to another
+
     * Convert a String representation of date/Time to another format.
     * format. The output string representation is formatted according tolocal timezone.
+
     * The string representation is interpreted according tolocal timezone.
 
     *  
 
     *  
     * @param date the date/time representation to convert
+
     * @param date  
     * @param formatIn the input date/time conversion pattern
+
    *            the date/time representation to convert
     * @param tZoneIn the input time zone
+
     * @param formatIn  
     * @param formatOut the output date/time conversion pattern
+
    *            the input date/time conversion pattern
     * @param tZoneOut the output time zone
+
     * @param tZoneIn  
     * @return the new string representation
+
    *            the input time zone to be used in conversion
 +
     * @param formatOut  
 +
    *            the output date/time conversion pattern
 +
     * @param tZoneOut  
 +
    *            the output time zone to be used in conversion
 +
     * @return the new String representation
 
     */
 
     */
 
     public static String convertString(String date, String formatIn, String tZoneIn, String formatOut, String tZoneOut)
 
     public static String convertString(String date, String formatIn, String tZoneIn, String formatOut, String tZoneOut)
  
 +
    /**
 +
    * Convert a String representation of date/Time to another format.
 +
    * The string representation is interpreted according to specified
 +
    * locale/timezone.
 +
    *
 +
    * @param date
 +
    *            the date/time representation to convert
 +
    * @param formatIn
 +
    *            the input date/time conversion pattern
 +
    * @param tZoneIn
 +
    *            the input time zone to be used in conversion
 +
    * @param langIn
 +
    *            the input locale to be used in conversion
 +
    * @param formatOut
 +
    *            the output date/time conversion pattern
 +
    * @param tZoneOut
 +
    *            the output time zone to be used in conversion
 +
    * @param langOut
 +
    *            the output locale to be used in conversion
 +
    * @return the new String representation
 +
    */
 +
    public static String convertString(String date, String formatIn, String tZoneIn, String langIn, String formatOut, String tZoneOut, String langOut)
  
 
     /**
 
     /**
     * Convert a {@link java.lang.String} representation of date/Time to another
+
     * Convert a String representation of date and an ordinal hour to another format.
     * format. The output string representation is formatted according to
+
     * The string representation is interpreted according to specified
     * <b>local</b> timezone.
+
     * locale/timezone.
 
     *  
 
     *  
     * @param date
+
     * @param date  
     *       the date/time representation to convert
+
     *             the date/time representation to convert
     * @param formatIn
+
     * @param formatIn  
     *       the input date/time conversion pattern
+
     *             the input date/time conversion pattern
     * @param tZoneIn
+
     * @param hour
     *       the input time zone
+
     *             the ordinal day hour [1..[23|24|25]
    * @param langIn
+
     * @param formatOut  
    *        the input locale to be used in conversion
+
     *             the output date/time conversion pattern
     * @param formatOut
+
     * @param tZoneOut  
     *       the output date/time conversion pattern
+
     *             the output time zone to be used in conversion
     * @param tZoneOut
+
     * @return the new String representation of date/time
     *       the output time zone
 
    * @param langOut
 
    *        the output locale to be used in conversion
 
     * @return the new string representation
 
 
     */
 
     */
    public static String convertString(String date, String formatIn, String tZoneIn, String langIn, String formatOut,
 
            String tZoneOut, String langOut)
 
 
 
     public static String convertDayHourString(String date, String formatIn, int hour, String formatOut, String tZoneOut)
 
     public static String convertDayHourString(String date, String formatIn, int hour, String formatOut, String tZoneOut)
 
  
 
     /**
 
     /**
     * Return a {@link java.lang.String} representation of the current date/time, according to local timezone.
+
     * Return a String representation of the current date/time, according to default timezone.
 
     *  
 
     *  
     * @param format the date/time conversion pattern
+
     * @param format  
     * @return the string representation of current date/time
+
    *            the date/time conversion pattern
 +
     * @return the String representation of current date/time
 
     */
 
     */
 
     public static String nowToString(String format)
 
     public static String nowToString(String format)
 
  
 
     /**
 
     /**
     * Return a {@link java.lang.String} representation of the current
+
     * Return a String representation of the current date/time, according to tZone timezone.
    * date/time, according to tZone timezone.
 
 
     *  
 
     *  
     * @param format the date/time conversion pattern
+
     * @param format  
     * @param tZone te destination timezone
+
    *            the date/time conversion pattern
     * @return the string representation of current date/time
+
     * @param tZone  
 +
    *            the destination timezone
 +
     * @return the String representation of current date/time
 
     */
 
     */
 
     public static String nowToString(String format, String tZone)
 
     public static String nowToString(String format, String tZone)
 
  
 
     /**
 
     /**
     * Return a {@link java.lang.String} representation of the current date/time, according to tZone timezone.
+
     * Return a String representation of the current date/time, according to tZone timezone
 +
    * and lang locale.
 
     *  
 
     *  
     * @param format the date/time conversion pattern
+
     * @param format  
     * @param tZone te destination timezone
+
    *            the date/time conversion pattern
     * @param lang the locale to be used in conversion
+
     * @param tZone  
     * @return the string representation of current date/time
+
    *            the destination timezone
 +
     * @param lang  
 +
    *            the locale to be used in conversion
 +
     * @return the String representation of current date/time
 
     */
 
     */
 
     public static String nowToString(String format, String tZone, String lang)
 
     public static String nowToString(String format, String tZone, String lang)
  
 
     /**
 
     /**
     * Return a {@link java.lang.String} representation, in teh given format, of tomorrow date.
+
     * Return a String representation, in the given format, of tomorrow date.
 
     *  
 
     *  
     * @param format the required format.
+
     * @param format  
     * @return a string representation of tomorrow.
+
    *            the required format.
 +
     * @return a String representation of tomorrow.
 
     */
 
     */
 
     public static String tomorrowToString(String format)
 
     public static String tomorrowToString(String format)
 +
</syntaxhighlight>
  
  
    /**
 
    * @return the tomorrow {@link java.util.Date} object
 
    */
 
    public static Date getTomorrow()
 
  
 
    /**
 
    * Compare two date/time represented as {@link java.lang.String} in the  given format.
 
    *
 
    * @return -1 if date1 < date2, 0 if date1 = date2, 1 if date1 > date2
 
    */
 
    public static int compare(String date1, String format1, String date2, String format2)
 
 
 
    /**
 
    * Compare two date/time represented as {@link java.lang.String} in the  given format and {@link java.util.Date}.
 
    *
 
    * @return -1 if date1 < date2, 0 if date1 = date2, 1 if date1 > date2
 
    */
 
    public static int compare(String date1, String format1, Date date2)
 
  
  
  
 +
* Special Date/Time access
 +
<syntaxhighlight lang="java5">
 
     /**
 
     /**
 
     * Return {@link java.util.Date} representing the first day of the week
 
     * Return {@link java.util.Date} representing the first day of the week
 
     * containing date.
 
     * containing date.
 
     *  
 
     *  
     * @param date
+
     * @param date the contained date
    *        the contained date
 
 
     * @return the first week day
 
     * @return the first week day
 
     */
 
     */
Line 227: Line 256:
 
     /**
 
     /**
 
     * Return {@link java.util.Date} representing the last day of the week
 
     * Return {@link java.util.Date} representing the last day of the week
     * containing <code>date</code>.
+
     * containing date.
 
     *  
 
     *  
     * @param date
+
     * @param date the contained date
    *        the contained date
 
 
     * @return the last week day
 
     * @return the last week day
 
     */
 
     */
Line 321: Line 349:
  
 
     /**
 
     /**
     * Return {@link java.lang.String} representing the last day of the month containing <code>date</code> in the given format.
+
     * Return {@link java.lang.String} representing the last day of the month containing date in the given format.
 
     *  
 
     *  
 
     * @param date the contained date
 
     * @param date the contained date
Line 399: Line 427:
 
     /**
 
     /**
 
     * Return {@link java.lang.String} representing the last day of the n't
 
     * Return {@link java.lang.String} representing the last day of the n't
     * <code>quarter</code> of <code>year</code>, in the given format.
+
     * quarter of year, in the given format.
 
     *  
 
     *  
     * @param quarter
+
     * @param quarter the requested quarter
    *        the requested quarter
+
     * @param year the requested year
     * @param year
+
     * @param format the output date format
    *        the requested year
 
     * @param format
 
    *        the output date format
 
 
     * @return the last quarter day
 
     * @return the last quarter day
 
     */
 
     */
Line 412: Line 437:
  
 
     /**
 
     /**
     * Change the date/time represented as {@link java.lang.String} in the given format. The parameters type and value must be the same of {@link java.util.Calendar}.
+
    * Return true if the given date is outside the daylight saving time.
 +
    *
 +
    * @param date
 +
    * @return
 +
    */
 +
    public static boolean isDaySolar(Date date)
 +
 
 +
    /**
 +
    * Return true if the given date, represented as {@link java.lang.String} in the given format,
 +
    * is outside the daylight saving time.
 +
    *
 +
    * @param date
 +
    * @return
 +
    */
 +
    public static boolean isDaySolar(String data, String format)
 +
 
 +
    /**
 +
    * Return true if the given date is in the daylight saving time.
 +
    *
 +
    * @param date
 +
    * @return
 +
    */
 +
    public static boolean isDayLegal(Date data)
 +
 
 +
    /**
 +
    * Return true if the given date, represented as {@link java.lang.String} in the given format,
 +
    * is in the daylight saving time.
 +
    *
 +
    * @param date
 +
    * @return
 +
    */
 +
    public static boolean isDayLegal(String data, String format)
 +
 
 +
    /**
 +
    * Return true if the given date is the transition day to/from daylight saving time.
 +
    *
 +
    * @param date
 +
    * @return
 +
    */
 +
    public static boolean isDayOfHourChange(Date data)
 +
 
 +
    /**
 +
    * Return true if the given date, represented as {@link java.lang.String} in the given format,
 +
    * is the transition day to/from daylight saving time.
 +
    *
 +
    * @param date
 +
    * @return
 +
    */
 +
    public static boolean isDayOfHourChange(String data, String format)
 +
 
 +
    /**
 +
    * Return the transition day to daylight saving time for the current year.
 +
    *
 +
    * @param date
 +
    * @return
 +
    */
 +
    public static Date getDayOfSolarToLegalChange()
 +
 
 +
    /**
 +
    * Return the transition day to daylight saving time for the given year.
 +
    *
 +
    * @param date
 +
    * @return
 +
    */
 +
    public static Date getDayOfSolarToLegalChange(int year)
 +
 
 +
    public static boolean isDayOfSolarToLegalChange(Date date)
 +
 
 +
    public static boolean isDayOfSolarToLegalChange(String date, String format)
 +
 
 +
    public static boolean encloseDayOfSolarToLegalChange(String date1, String format1, String date2, String format2)
 +
 
 +
    public static boolean encloseDayOfSolarToLegalChange(Date date1, Date date2)
 +
 
 +
    public static boolean encloseDayOfSolarToLegalChange(Calendar date1, Calendar date2)
 +
 
 +
    public static Date getDayOfLegalToSolarChange()
 +
 
 +
    public static Date getDayOfLegalToSolarChange(int year)
 +
 
 +
    public static boolean isDayOfLegalToSolarChange(Date date)
 +
 
 +
    public static boolean isDayOfLegalToSolarChange(String date, String format)
 +
 
 +
    public static boolean encloseDayOfLegalToSolarChange(String date1, String format1, String date2, String format2)
 +
 
 +
    public static boolean encloseDayOfLegalToSolarChange(Date date1, Date date2)
 +
 
 +
    public static boolean encloseDayOfLegalToSolarChange(Calendar date1, Calendar date2)
 +
 
 +
    public static boolean encloseDayOfHourChange(String date1, String format1, String date2, String format2)
 +
 
 +
    public static boolean encloseDayOfHourChange(Date date1, Date date2)
 +
 
 +
    public static boolean encloseDayOfHourChange(Calendar date1, Calendar date2)
 +
 
 +
    /**
 +
    * @return the haveEasterDay
 +
    */
 +
    public static boolean haveEasterDay()
 +
 
 +
    /**
 +
    * Calculate Easter Sunday.
 +
    * This algorithm holds for any year in the Gregorian Calendar,
 +
    * which (of course) means years including and after 1583.
 +
    *
 +
    * @param nYear
 +
    *        4 digit year
 +
    */
 +
    public static Calendar getEasterSunday(int nYear)
 +
</syntaxhighlight>
 +
 
 +
 
 +
* Date/Time manipulation
 +
<syntaxhighlight lang="java5">
 +
  /**
 +
    * Returns the default Locale instance used by DateUtils.
 +
    **/
 +
    public static Locale getDefaultLocale()
 +
 
 +
    /**
 +
    * Returns the default TimeZone instance used by DateUtils.
 +
    **/
 +
    public static TimeZone getDefaultTimeZone()
 +
 
 +
    /**
 +
    * Create a Calendar instance with default timezone.
 +
    **/
 +
    public static Calendar createCalendar()
 +
 
 +
    /**
 +
    * @return the tomorrow {@link java.util.Date} object
 +
    */
 +
    public static Date getTomorrow()
 +
 
 +
 
 +
    /**
 +
    * Compare two date/time represented as {@link java.lang.String} in the  given format.
 +
    *
 +
    * @return -1 if date1 < date2, 0 if date1 = date2, 1 if date1 > date2
 +
    */
 +
    public static int compare(String date1, String format1, String date2, String format2)
 +
 
 +
 
 +
    /**
 +
    * Compare two date/time represented as {@link java.lang.String} in the  given format and {@link java.util.Date}.
 +
    *
 +
    * @return -1 if date1 < date2, 0 if date1 = date2, 1 if date1 > date2
 +
    */
 +
    public static int compare(String date1, String format1, Date date2)
 +
 
 +
 
 +
 
 +
 
 +
    /**
 +
     * Change the date/time represented as {@link java.lang.String} in the given format.
 +
    * The parameters type and value must be the same of {@link java.util.Calendar}.
 
     *  
 
     *  
 
     * @param date the date/time to change
 
     * @param date the date/time to change
Line 423: Line 604:
  
 
     /**
 
     /**
     * Change the date/time represented as {@link java.util.Date}. The parameters type and value must be the same of {@link java.util.Calendar}.
+
     * Change the date/time represented as {@link java.util.Date}.  
 +
    * The parameters type and value must be the same of {@link java.util.Calendar}.
 
     *  
 
     *  
 
     * @param date the date/time to change
 
     * @param date the date/time to change
Line 433: Line 615:
  
 
     /**
 
     /**
     * Change the date/time represented as {@link java.lang.String} in the given
+
     * Change the date/time represented as {@link java.lang.String} in the given format.
     * format. The parameters <code>type</code> and <code>value</code> must be
+
     * The parameters type and value must be the same of {@link java.util.Calendar}.
    * the same of {@link java.util.Calendar}.
 
 
     *  
 
     *  
 
     * @param date
 
     * @param date
Line 450: Line 631:
  
 
     /**
 
     /**
     * Change the date/time represented as {@link java.lang.String} in the given
+
     * Change the date/time represented as {@link java.lang.String} in the given format.
     * format. The parameters <code>type</code> and <code>value</code> must be
+
     * The parameters type and value must be the same of {@link java.util.Calendar}.
    * the same of {@link java.util.Calendar}.
 
 
     *  
 
     *  
     * @param date
+
     * @param date the date/time to change
    *        the date/time to change
+
     * @param format the date/time conversion pattern
     * @param format
+
     * @param type the field to change
    *        the date/time conversion pattern
+
     * @param value the offset value
     * @param type
 
    *        the field to change
 
     * @param value
 
    *        the offset value
 
 
     * @return the modified date
 
     * @return the modified date
 
     */
 
     */
Line 467: Line 643:
  
 
     /**
 
     /**
     * Change the date/time represented as {@link java.util.Date}. The
+
     * Change the date/time represented as {@link java.util.Date}.
     * parameters <code>type</code> and <code>value</code> must be the same of
+
     * The parameters type and value must be the same of {@link java.util.Calendar}.
    * {@link java.util.Calendar}.
 
 
     *  
 
     *  
     * @param date
+
     * @param date the date/time to change
    *        the date/time to change
+
     * @param type the field to change
     * @param type
+
     * @param value the offset value
    *        the field to change
 
     * @param value
 
    *        the offset value
 
 
     * @return the modified date
 
     * @return the modified date
 
     */
 
     */
Line 482: Line 654:
  
 
     /**
 
     /**
     * Change the current date/time. The parameters <code>type</code> and
+
     * Change the current date/time. The parameters type and
     * <code>value</code> must be the same of {@link java.util.Calendar}.
+
     * value must be the same of {@link java.util.Calendar}.
 
     *  
 
     *  
     * @param type
+
     * @param type the field to change
    *        the field to change
+
     * @param value the offset value
     * @param value
 
    *        the offset value
 
 
     * @param onlyDate
 
     * @param onlyDate
     *       if true the following fields are resetted: Calendar.HOUR_OF_DAY
+
     * if true the following fields are resetted: Calendar.HOUR_OF_DAY
 
     *        Calendar.MINUTE Calendar.SECOND Calendar.MILLISECOND
 
     *        Calendar.MINUTE Calendar.SECOND Calendar.MILLISECOND
 
     * @return the modified date
 
     * @return the modified date
Line 497: Line 667:
  
 
     /**
 
     /**
     * Copy the following fields of the date/time <code>date2</code> to
+
     * Copy the following fields of the date/time date2 to
     * <code>date1</code>, represented as {@link java.util.Date}:
+
     * date1, represented as {@link java.util.Date}:
 
     * Calendar.DAY_OF_MONTH Calendar.MONTH Calendar.YEAR
 
     * Calendar.DAY_OF_MONTH Calendar.MONTH Calendar.YEAR
 
     *  
 
     *  
     * @param date1
+
     * @param date1 the date/time to change
    *        the date/time to change
+
     * @param date2 the source date/time
     * @param date2
 
    *        the source date/time
 
 
     * @return the modified date1
 
     * @return the modified date1
 
     */
 
     */
Line 510: Line 678:
  
 
     /**
 
     /**
     * Copy the following fields of the date/time <code>date2</code> to
+
     * Copy the following fields of the date/time date2 to
     * <code>date1</code>, represented as {@link java.util.Calendar}:
+
     * date1, represented as {@link java.util.Calendar}:
 
     * Calendar.DAY_OF_MONTH Calendar.MONTH Calendar.YEAR
 
     * Calendar.DAY_OF_MONTH Calendar.MONTH Calendar.YEAR
 
     *  
 
     *  
     * @param date1
+
     * @param date1 the date/time to change
    *        the date/time to change
+
     * @param date2 the source date/time
     * @param date2
 
    *        the source date/time
 
 
     * @return the modified date1
 
     * @return the modified date1
 
     */
 
     */
Line 523: Line 689:
  
 
     /**
 
     /**
     * Copy the following fields of the date/time <code>date2</code> to
+
     * Copy the following fields of the date/time date2 to
     * <code>date1</code>, represented as {@link java.util.Date}:
+
     * date1, represented as {@link java.util.Date}:
 
     * Calendar.HOUR_OF_DAY Calendar.MINUTE Calendar.SECOND Calendar.MILLISECOND
 
     * Calendar.HOUR_OF_DAY Calendar.MINUTE Calendar.SECOND Calendar.MILLISECOND
 
     *  
 
     *  
     * @param date1
+
     * @param date1 the date/time to change
    *        the date/time to change
+
     * @param date2 the source date/time
     * @param date2
 
    *        the source date/time
 
 
     * @return the modified date1
 
     * @return the modified date1
 
     */
 
     */
Line 536: Line 700:
  
 
     /**
 
     /**
     * Copy the following fields of the date/time <code>date2</code> to
+
     * Copy the following fields of the date/time date2 to
     * <code>date1</code>, represented as {@link java.util.Calendar}:
+
     * date1, represented as {@link java.util.Calendar}:
 
     * Calendar.HOUR_OF_DAY Calendar.MINUTE Calendar.SECOND Calendar.MILLISECOND
 
     * Calendar.HOUR_OF_DAY Calendar.MINUTE Calendar.SECOND Calendar.MILLISECOND
 
     *  
 
     *  
     * @param date1
+
     * @param date1 the date/time to change
    *        the date/time to change
+
     * @param date2 the source date/time
     * @param date2
 
    *        the source date/time
 
 
     * @return the modified date1
 
     * @return the modified date1
 
     */
 
     */
Line 553: Line 715:
 
     * Calendar.SECOND Calendar.MILLISECOND
 
     * Calendar.SECOND Calendar.MILLISECOND
 
     *  
 
     *  
     * @param date
+
     * @param date the date/time to change
    *        the date/time to change
 
 
     * @return the modified date
 
     * @return the modified date
 
     */
 
     */
Line 564: Line 725:
 
     * Calendar.SECOND Calendar.MILLISECOND
 
     * Calendar.SECOND Calendar.MILLISECOND
 
     *  
 
     *  
     * @param date
+
     * @param date the date/time to change
    *        the date/time to change
 
 
     * @return the modified date
 
     * @return the modified date
 
     */
 
     */
Line 575: Line 735:
 
     * Calendar.SECOND Calendar.MILLISECOND
 
     * Calendar.SECOND Calendar.MILLISECOND
 
     *  
 
     *  
     * @param date
+
     * @param date the date/time to change
    *        the date/time to change
 
 
     * @return the modified date
 
     * @return the modified date
 
     */
 
     */
Line 586: Line 745:
 
     * Calendar.SECOND Calendar.MILLISECOND
 
     * Calendar.SECOND Calendar.MILLISECOND
 
     *  
 
     *  
     * @param date
+
     * @param date the date/time to change
    *        the date/time to change
 
 
     * @return the modified date
 
     * @return the modified date
 
     */
 
     */
Line 597: Line 755:
 
     * Calendar.SECOND Calendar.MILLISECOND
 
     * Calendar.SECOND Calendar.MILLISECOND
 
     *  
 
     *  
     * @param date
+
     * @param date the date/time to change
    *        the date/time to change
 
 
     * @return the modified date
 
     * @return the modified date
 
     */
 
     */
Line 608: Line 765:
 
     * Calendar.SECOND Calendar.MILLISECOND
 
     * Calendar.SECOND Calendar.MILLISECOND
 
     *  
 
     *  
     * @param date
+
     * @param date the date/time to change
    *        the date/time to change
 
 
     * @return the modified date
 
     * @return the modified date
 
     */
 
     */
Line 615: Line 771:
  
 
     /**
 
     /**
     * Generate a range of days starting from <code>date1</code> till
+
     * Generate a range of days starting from date1 till
     * <code>date2</code>, represented as {@link java.lang.String} in the given
+
     * date2, represented as {@link java.lang.String} in the given
 
     * format.
 
     * format.
 
     *  
 
     *  
     * @param date1
+
     * @param date1 start date (inclusive)
    *        start date (inclusive)
+
     * @param format1 format of start date
     * @param format1
+
     * @param date2 end date (inclusive)
    *        format of start date
+
     * @param format2 format of end date
     * @param date2
 
    *        end date (inclusive)
 
     * @param format2
 
    *        format of end date
 
 
     * @return an array of {@link java.util.Date}
 
     * @return an array of {@link java.util.Date}
 
     */
 
     */
Line 632: Line 784:
  
 
     /**
 
     /**
     * Generate a range of days starting from <code>date1</code> till
+
     * Generate a range of days starting from date1 till
     * <code>date2</code>, represented as {@link java.util.Date}.
+
     * date2, represented as {@link java.util.Date}.
 
     *  
 
     *  
     * @param date1
+
     * @param date1 start date (inclusive)
    *        start date (inclusive)
+
     * @param date2 end date (inclusive)
     * @param date2
 
    *        end date (inclusive)
 
 
     * @return an array of {@link java.util.Date}
 
     * @return an array of {@link java.util.Date}
 
     */
 
     */
Line 645: Line 795:
  
 
     /**
 
     /**
     * Generate a range of days starting from <code>date1</code> till
+
     * Generate a range of days starting from date1 tilldate2, represented as {@link java.util.Calendar}.
    * <code>date2</code>, represented as {@link java.util.Calendar}.
 
 
     *  
 
     *  
     * @param date1
+
     * @param date1 start date (inclusive)
    *        start date (inclusive)
+
     * @param date2 end date (inclusive)
     * @param date2
 
    *        end date (inclusive)
 
 
     * @return an array of {@link java.util.Date}
 
     * @return an array of {@link java.util.Date}
 
     */
 
     */
Line 657: Line 804:
  
 
     /**
 
     /**
     * Return the days difference as <code>date2</code> - <code>date1</code>,
+
     * Return the days difference as date2 - date1, represented as {@link java.util.Date}.
    * represented as {@link java.util.Date}.
 
 
     *  
 
     *  
 
     * @param date1
 
     * @param date1
Line 668: Line 814:
  
 
     /**
 
     /**
     * Return the days difference as <code>date2</code> - <code>date1</code>,
+
     * Return the days difference as date2 - date1, represented as {@link java.lang.String} in the given format.
    * represented as {@link java.lang.String} in the given format.
 
 
     *  
 
     *  
 
     * @param date1
 
     * @param date1
Line 680: Line 825:
 
     public static DateDiff getDiff(String date1, String format1, String date2, String format2, TimeZone tZone)
 
     public static DateDiff getDiff(String date1, String format1, String date2, String format2, TimeZone tZone)
  
    /**
 
    * Return true if the given date is outside the daylight saving time.
 
    *
 
    * @param date
 
    * @return
 
    */
 
    public static boolean isDaySolar(Date date)
 
 
    /**
 
    * Return true if the given date, represented as {@link java.lang.String} in
 
    * the given format,
 
    * is outside the daylight saving time.
 
    *
 
    * @param date
 
    * @return
 
    */
 
    public static boolean isDaySolar(String data, String format)
 
 
    /**
 
    * Return true if the given date is in the daylight saving time.
 
    *
 
    * @param date
 
    * @return
 
    */
 
    public static boolean isDayLegal(Date data)
 
 
    /**
 
    * Return true if the given date, represented as {@link java.lang.String} in
 
    * the given format,
 
    * is in the daylight saving time.
 
    *
 
    * @param date
 
    * @return
 
    */
 
    public static boolean isDayLegal(String data, String format)
 
 
    /**
 
    * Return true if the given date is the transition day to/from daylight
 
    * saving time.
 
    *
 
    * @param date
 
    * @return
 
    */
 
    public static boolean isDayOfHourChange(Date data)
 
 
    /**
 
    * Return true if the given date, represented as {@link java.lang.String} in
 
    * the given format,
 
    * is the transition day to/from daylight saving time.
 
    *
 
    * @param date
 
    * @return
 
    */
 
    public static boolean isDayOfHourChange(String data, String format)
 
 
    /**
 
    * Return the transition day to daylight saving time for the current year.
 
    *
 
    * @param date
 
    * @return
 
    */
 
    public static Date getDayOfSolarToLegalChange()
 
 
    /**
 
    * Return the transition day to daylight saving time for the given
 
    * <code>year</code>.
 
    *
 
    * @param date
 
    * @return
 
    */
 
    public static Date getDayOfSolarToLegalChange(int year)
 
 
    public static boolean isDayOfSolarToLegalChange(Date date)
 
 
    public static boolean isDayOfSolarToLegalChange(String date, String format)
 
 
    public static boolean encloseDayOfSolarToLegalChange(String date1, String format1, String date2, String format2)
 
 
    public static boolean encloseDayOfSolarToLegalChange(Date date1, Date date2)
 
 
    public static boolean encloseDayOfSolarToLegalChange(Calendar date1, Calendar date2)
 
 
    public static Date getDayOfLegalToSolarChange()
 
 
    public static Date getDayOfLegalToSolarChange(int year)
 
 
    public static boolean isDayOfLegalToSolarChange(Date date)
 
 
    public static boolean isDayOfLegalToSolarChange(String date, String format)
 
    {
 
        return isDayOfLegalToSolarChange(DateUtils.stringToDate(date, format));
 
    }
 
 
    public static boolean encloseDayOfLegalToSolarChange(String date1, String format1, String date2, String format2)
 
    {
 
        return encloseDayOfLegalToSolarChange(stringToDate(date1, format1), stringToDate(date2, format2));
 
    }
 
 
    public static boolean encloseDayOfLegalToSolarChange(Date date1, Date date2)
 
    {
 
        Calendar d1 = createCalendar();
 
        d1.setTime(date1);
 
        Calendar d2 = createCalendar();
 
        d2.setTime(date2);
 
        return encloseDayOfLegalToSolarChange(d1, d2);
 
    }
 
 
    public static boolean encloseDayOfLegalToSolarChange(Calendar date1, Calendar date2)
 
    {
 
        Calendar lts1 = createCalendar();
 
        lts1.setTime(getDayOfLegalToSolarChange(date1.get(Calendar.YEAR)));
 
        Calendar lts2 = createCalendar();
 
        lts2.setTime(getDayOfLegalToSolarChange(date2.get(Calendar.YEAR)));
 
        return ((date1.before(lts1) || date1.equals(lts1)) && (lts1.equals(date2) || lts1.before(date2)))
 
                || ((date1.before(lts2) || date1.equals(lts2)) && (lts2.equals(date2) || lts2.before(date2)));
 
    }
 
 
    public static boolean encloseDayOfHourChange(String date1, String format1, String date2, String format2)
 
    {
 
        return encloseDayOfHourChange(stringToDate(date1, format1), stringToDate(date2, format2));
 
    }
 
 
    public static boolean encloseDayOfHourChange(Date date1, Date date2)
 
    {
 
        Calendar d1 = createCalendar();
 
        d1.setTime(date1);
 
        Calendar d2 = createCalendar();
 
        d2.setTime(date2);
 
        return encloseDayOfHourChange(d1, d2);
 
    }
 
 
    public static boolean encloseDayOfHourChange(Calendar date1, Calendar date2)
 
  
 
     public static int numHoursInDay(Date date)
 
     public static int numHoursInDay(Date date)
Line 828: Line 841:
  
 
     public static boolean checkDayType(int dayType, Date day) throws IllegalStateException
 
     public static boolean checkDayType(int dayType, Date day) throws IllegalStateException
 
 
 
    /**
 
    * @return the haveEasterDay
 
    */
 
    public static boolean haveEasterDay()
 
 
    /**
 
    * Calculate Easter Sunday Written by Gregory N. Mirsky
 
    * Source: 2nd Edition by Peter Duffett-Smith.
 
    * It was originally from Butcher's Ecclesiastical Calendar, published in
 
    * 1876.
 
    * This algorithm has also been published in the 1922 book General Astronomy
 
    * by Spencer Jones
 
    * in The Journal of the British Astronomical Association (Vol.88, page 91,
 
    * December 1977) and in
 
    * Astronomical Algorithms (1991) by Jean Meeus.
 
    * This algorithm holds for any year in the Gregorian Calendar, which (of
 
    * course) means years
 
    * including and after 1583.
 
    *
 
    * <pre>
 
    * a=year%19
 
    * b=year/100
 
    * c=year%100
 
    * d=b/4 e=b%4
 
    * f=(b+8)/25
 
    * g=(b-f+1)/3
 
    * h=(19a+b-d-g+15)%30
 
    * i=c/4 k=c%4
 
    * l=(32+2e+2i-h-k)%7
 
    * m=(a+11h+22l)/451
 
    * Easter Month =(h+l-7m+114)/31 [3=March, 4=April]
 
    * p=(h+l-7m+114)%31
 
    * Easter Date=p+1 (date in Easter Month)
 
    * </pre>
 
    *
 
    * Note: Integer truncation is already factored into the calculations. Using
 
    * higher
 
    * percision variables will cause inaccurate calculations.
 
    *
 
    * @param nYear
 
    *        4 digit year
 
    */
 
    public static Calendar getEasterSunday(int nYear)
 
 
    private static synchronized boolean isEasterMonday(Calendar day)
 
    {
 
        int nYear = day.get(Calendar.YEAR);
 
        if ((lastYear == -1) || (lastYear != nYear) || (dEasterMonday == null)) {
 
            dEasterMonday = getEasterSunday(nYear);
 
            dEasterMonday.add(Calendar.DAY_OF_MONTH, 1);
 
            lastYear = nYear;
 
        }
 
        if (dEasterMonday.equals(day)) {
 
            return true;
 
        }
 
        return false;
 
    }
 
 
    private static boolean isConfiguredAsHoliday(Calendar day) throws IllegalStateException
 
 
    /**
 
    * Return a DateFormat capable of handling the given conversion
 
    * pattern. The formatters are cached after creation. By default, the
 
    * formatters format dates according to the <b>local</b> timezone.
 
    *
 
    * @param format
 
    *        to conversion pattern to handle
 
    * @return the requested DateFormat instance
 
    */
 
    private static synchronized DateFormat getFormatter(String format)
 
 
    /**
 
    * @version 3.0.0 Feb 17, 2010
 
    * @author GreenVulcano Developer Team
 
    *
 
    *        DateFormat to handle FORMAT_SYSTEM_TIME
 
    */
 
    private static class SystemTimeDateFormat extends DateFormat
 
 
    /**
 
    * Return a DateFormat capable of handling the given conversion
 
    * pattern for the <b>tZone</b> timezone.
 
    *
 
    * @param format
 
    *        the conversion pattern to handle
 
    * @param tZone
 
    *        the timezone to handle
 
    * @return the requested DateFormat instance
 
    */
 
    private static synchronized DateFormat getFormatter(String tZone, String format)
 
 
    private static long toSystemTime(Object input)
 
 
    private static Calendar systemTimeToCalendar(String input)
 
 
    private static Date systemTimeToDate(String input)
 
 
</syntaxhighlight>
 
</syntaxhighlight>

Latest revision as of 13:37, 22 May 2012

Class FQN: it.greenvulcano.util.txt.DateUtils

Following the DateUtils public constants

    /**
     * The conversion pattern to be used for input string that represent an OS timestamp.
     */
    String FORMAT_SYSTEM_TIME       = "SYSTEM_TIME";

    /**
     * Short ISO date/time format
     */
    String FORMAT_ISO_DATE_S        = "yyyyMMdd";
    String FORMAT_ISO_TIME_S        = "HHmmss";
    String FORMAT_ISO_DATETIME_S    = "yyyyMMdd HHmmss";
    String FORMAT_ISO_TIMESTAMP_S   = "yyyyMMdd HHmmssSSS";
    /**
     * Long ISO date/time format
     */
    String FORMAT_ISO_DATE_L        = "yyyy-MM-dd";
    String FORMAT_ISO_TIME_L        = "HH:mm:ss";
    String FORMAT_ISO_DATETIME_L    = "yyyy-MM-dd HH:mm:ss";
    String FORMAT_ISO_TIMESTAMP_L   = "yyyy-MM-dd HH:mm:ss.SSS";
    /**
     * ISO date/time + UTC format
     */
    String FORMAT_ISO_DATETIME_UTC  = "yyyy-MM-dd'T'HH:mm:ssZ";
    /**
     * IETF date/time format
     */
    String FORMAT_IETF_DATETIME     = "EEE, d MMM yyyy HH:mm:ss z";

    String DEFAULT_FORMAT_DATE      = FORMAT_ISO_DATE_L;
    String DEFAULT_FORMAT_TIME      = FORMAT_ISO_TIME_L;
    String DEFAULT_FORMAT_DATETIME  = FORMAT_ISO_DATETIME_L;
    String DEFAULT_FORMAT_TIMESTAMP = FORMAT_ISO_TIMESTAMP_L;

Following the DateUtils public static methods

  • Date/Time conversion
    /**
     * Convert a String date representation to a Date instance.
     * 
     * @param date 
     *             the string representation of Date/Time
     * @param format 
     *             the conversion pattern
     * @return a Date instance
     */
    public static Date stringToDate(String date, String format)

    /**
     * Convert a String date representation to a Date instance.
     * 
     * @param date 
     *             the string representation of Date/Time
     * @param format 
     *             the conversion pattern
     * @param tZone 
     *             the TimeZone to be used in conversion
     * @return a Date instance
     */
    public static Date stringToDate(String date, String format, String tZone)

    /**
     * Convert a String date representation to a Date instance.
     * 
     * @param date 
     *             the string representation of Date/Time
     * @param format 
     *             the conversion pattern
     * @param tZone 
     *             the TimeZone to be used in conversion
     * @param lang 
     *             the Locale to be used in conversion
     * @return a Date instance
     */
    public static Date stringToDate(String date, String format, String tZone, String lang)

    /**
     * Convert a Date instance to a String representation.
     * 
     * @param date 
     *             the Date instance to convert
     * @param format 
     *             the conversion pattern
     * @return a String representation of date
     */
    public static String dateToString(Date date, String format)

    /**
     * Convert a Date instance to a String representation.
     * 
     * @param date 
     *             the Date instance to convert
     * @param format 
     *             the conversion pattern
     * @param tZone 
     *             the TimeZone to be used in conversion
     * @return a String representation of date
     */
    public static String dateToString(Date date, String format, String tZone)

    /**
     * Convert a Date instance to a String representation.
     * 
     * @param date 
     *             the Date instance to convert
     * @param format 
     *             the conversion pattern
     * @param tZone 
     *             the TimeZone to be used in conversion
     * @param lang 
     *             the Locale to be used in conversion
     * @return a String representation of date
     */
    public static String dateToString(Date date, String format, String tZone, String lang)

    /**
     * Convert a String representation of date/Time to another format. 
     * The string representation is interpreted according to
     * default locale/timezone.
     * 
     * @param date 
     *             the date/time representation to convert
     * @param formatIn 
     *             the input date/time conversion pattern
     * @param formatOut 
     *             the output date/time conversion pattern
     * @return the new String representation
     */
    public static String convertString(String date, String formatIn, String formatOut)

    /**
     * Convert a String representation of date/Time to another format. 
     * The string representation is interpreted according tolocal timezone.
     * 
     * @param date 
     *             the date/time representation to convert
     * @param formatIn 
     *             the input date/time conversion pattern
     * @param tZoneIn 
     *             the input time zone to be used in conversion
     * @param formatOut 
     *             the output date/time conversion pattern
     * @param tZoneOut 
     *             the output time zone to be used in conversion
     * @return the new String representation
     */
    public static String convertString(String date, String formatIn, String tZoneIn, String formatOut, String tZoneOut)

    /**
     * Convert a String representation of date/Time to another format. 
     * The string representation is interpreted according to specified
     * locale/timezone.
     * 
     * @param date 
     *             the date/time representation to convert
     * @param formatIn 
     *             the input date/time conversion pattern
     * @param tZoneIn 
     *             the input time zone to be used in conversion
     * @param langIn 
     *             the input locale to be used in conversion
     * @param formatOut 
     *             the output date/time conversion pattern
     * @param tZoneOut 
     *             the output time zone to be used in conversion
     * @param langOut 
     *             the output locale to be used in conversion
     * @return the new String representation
     */
    public static String convertString(String date, String formatIn, String tZoneIn, String langIn, String formatOut, String tZoneOut, String langOut)

    /**
     * Convert a String representation of date and an ordinal hour to another format. 
     * The string representation is interpreted according to specified
     * locale/timezone.
     * 
     * @param date 
     *             the date/time representation to convert
     * @param formatIn 
     *             the input date/time conversion pattern
     * @param hour 
     *             the ordinal day hour [1..[23|24|25]
     * @param formatOut 
     *             the output date/time conversion pattern
     * @param tZoneOut 
     *             the output time zone to be used in conversion
     * @return the new String representation of date/time
     */
    public static String convertDayHourString(String date, String formatIn, int hour, String formatOut, String tZoneOut)

    /**
     * Return a String representation of the current date/time, according to default timezone.
     * 
     * @param format 
     *             the date/time conversion pattern
     * @return the String representation of current date/time
     */
    public static String nowToString(String format)

    /**
     * Return a String representation of the current date/time, according to tZone timezone.
     * 
     * @param format 
     *             the date/time conversion pattern
     * @param tZone 
     *             the destination timezone
     * @return the String representation of current date/time
     */
    public static String nowToString(String format, String tZone)

    /**
     * Return a String representation of the current date/time, according to tZone timezone
     * and lang locale.
     * 
     * @param format 
     *             the date/time conversion pattern
     * @param tZone 
     *             the destination timezone
     * @param lang 
     *             the locale to be used in conversion
     * @return the String representation of current date/time
     */
    public static String nowToString(String format, String tZone, String lang)

    /**
     * Return a String representation, in the given format, of tomorrow date.
     * 
     * @param format 
     *             the required format.
     * @return a String representation of tomorrow.
     */
    public static String tomorrowToString(String format)




  • Special Date/Time access
    /**
     * Return {@link java.util.Date} representing the first day of the week
     * containing date.
     * 
     * @param date the contained date
     * @return the first week day
     */
    public static Date getWeekStart(Date date)


    /**
     * Return {@link java.util.Date} representing the last day of the week
     * containing date.
     * 
     * @param date the contained date
     * @return the last week day
     */
    public static Date getWeekEnd(Date date)


    /**
     * Return {@link java.util.Date} representing the first day of the n't  week of year.
     * 
     * @param week the requested week
     * @param year the requested year
     * @return the first week day
     */
    public static Date getWeekStart(int week, int year)


    /**
     * Return {@link java.util.Date} representing the last day of the n't week of year.
     * 
     * @param week the requested week
     * @param year the requested year
     * @return the last week day
     */
    public static Date getWeekEnd(int week, int year)

    /**
     * Return {@link java.lang.String} representing the first day of the week containing datein the given format.
     * 
     * @param date the contained date
     * @param format the input/output date format
     * @return the first week day
     */
    public static String getWeekStart(String date, String format)
 
    /**
     * Return {@link java.lang.String} representing the last day of the week containing date in the given format.
     * 
     * @param date the contained date
     * @param format the input/output date format
     * @return the last week day
     */
    public static String getWeekEnd(String date, String format)

    /**
     * Return {@link java.lang.String} representing the first day of the n't week of year, in the given format.
     * 
     * @param week the requested week
     * @param year the requested year
     * @param format the output date format
     * @return the first week day
     */
    public static String getWeekStart(String week, String year, String format)


    /**
     * Return {@link java.lang.String} representing the last day of the n't week of year, in the given format.
     * 
     * @param week the requested week
     * @param year the requested year
     * @param format the output date format
     * @return the last week day
     */
    public static String getWeekEnd(String week, String year, String format)
 
    /**
     * Return {@link java.util.Date} representing the first day of the month containing date.
     * 
     * @param date the contained date
     * @return the first month day
     */
    public static Date getMonthStart(Date date)

    /**
     * Return {@link java.util.Date} representing the last day of the month containing date.
     * 
     * @param date the contained date
     * @return the last month day
     */
    public static Date getMonthEnd(Date date)
 

    /**
     * Return {@link java.lang.String} representing the first day of the month containing date in the given format.
     * 
     * @param date the contained date
     * @param format the input/output date format
     * @return the first month day
     */
    public static String getMonthStart(String date, String format)

    /**
     * Return {@link java.lang.String} representing the last day of the month containing date in the given format.
     * 
     * @param date the contained date
     * @param format the input/output date format
     * @return the last month day
     */
    public static String getMonthEnd(String date, String format)

    /**
     * Return {@link java.util.Date} representing the first day of the n't month of year.
     * 
     * @param month the requested month
     * @param year the requested year
     * @return the first month day
     */
    public static Date getMonthStart(int month, int year)


    /**
     * Return {@link java.util.Date} representing the last day of the n't month of year.
     * 
     * @param month the requested month
     * @param year the requested year
     * @return the last month day
     */
    public static Date getMonthEnd(int month, int year)

    /**
     * Return {@link java.lang.String} representing the first day of the n't month of year, in the given format.
     * 
     * @param month the requested month
     * @param year the requested year
     * @param format the output date format
     * @return the first month day
     */
    public static String getMonthStart(String month, String year, String format)

    /**
     * Return {@link java.lang.String} representing the last day of the n't month of year, in the given format.
     * 
     * @param month the requested month
     * @param year the requested year
     * @param format the output date format
     * @return the last month day
     */
    public static String getMonthEnd(String month, String year, String format)

    /**
     * Return {@link java.util.Date} representing the first day of the n't quarter of year.
     * 
     * @param quarter  the requested quarter
     * @param year the requested year
     * @return the first quarter day
     */
    public static Date getQuarterStart(int quarter, int year)


    /**
     * Return {@link java.util.Date} representing the last day of the n't quarter of year.
     * 
     * @param quarter the requested quarter
     * @param year the requested year
     * @return the last quarter day
     */
    public static Date getQuarterEnd(int quarter, int year)

    /**
     * Return {@link java.lang.String} representing the first day of the n't quarter of year, in the given format.
     * 
     * @param quarter the requested quarter
     * @param year he requested year
     * @param format the output date format
     * @return the first quarter day
     */
    public static String getQuarterStart(String quarter, String year, String format)

    /**
     * Return {@link java.lang.String} representing the last day of the n't
     * quarter of year, in the given format.
     * 
     * @param quarter the requested quarter
     * @param year the requested year
     * @param format the output date format
     * @return the last quarter day
     */
    public static String getQuarterEnd(String quarter, String year, String format)

    /**
     * Return true if the given date is outside the daylight saving time.
     * 
     * @param date
     * @return
     */
    public static boolean isDaySolar(Date date)

    /**
     * Return true if the given date, represented as {@link java.lang.String} in the given format,
     * is outside the daylight saving time.
     * 
     * @param date
     * @return
     */
    public static boolean isDaySolar(String data, String format)

    /**
     * Return true if the given date is in the daylight saving time.
     * 
     * @param date
     * @return
     */
    public static boolean isDayLegal(Date data)

    /**
     * Return true if the given date, represented as {@link java.lang.String} in the given format,
     * is in the daylight saving time.
     * 
     * @param date
     * @return
     */
    public static boolean isDayLegal(String data, String format)

    /**
     * Return true if the given date is the transition day to/from daylight saving time.
     * 
     * @param date
     * @return
     */
    public static boolean isDayOfHourChange(Date data)

    /**
     * Return true if the given date, represented as {@link java.lang.String} in the given format,
     * is the transition day to/from daylight saving time.
     * 
     * @param date
     * @return
     */
    public static boolean isDayOfHourChange(String data, String format)

    /**
     * Return the transition day to daylight saving time for the current year.
     * 
     * @param date
     * @return
     */
    public static Date getDayOfSolarToLegalChange()

    /**
     * Return the transition day to daylight saving time for the given year.
     * 
     * @param date
     * @return
     */
    public static Date getDayOfSolarToLegalChange(int year)

    public static boolean isDayOfSolarToLegalChange(Date date)

    public static boolean isDayOfSolarToLegalChange(String date, String format)

    public static boolean encloseDayOfSolarToLegalChange(String date1, String format1, String date2, String format2)

    public static boolean encloseDayOfSolarToLegalChange(Date date1, Date date2)

    public static boolean encloseDayOfSolarToLegalChange(Calendar date1, Calendar date2)

    public static Date getDayOfLegalToSolarChange()

    public static Date getDayOfLegalToSolarChange(int year)

    public static boolean isDayOfLegalToSolarChange(Date date)

    public static boolean isDayOfLegalToSolarChange(String date, String format)

    public static boolean encloseDayOfLegalToSolarChange(String date1, String format1, String date2, String format2)

    public static boolean encloseDayOfLegalToSolarChange(Date date1, Date date2)

    public static boolean encloseDayOfLegalToSolarChange(Calendar date1, Calendar date2)

    public static boolean encloseDayOfHourChange(String date1, String format1, String date2, String format2)

    public static boolean encloseDayOfHourChange(Date date1, Date date2)

    public static boolean encloseDayOfHourChange(Calendar date1, Calendar date2)

    /**
     * @return the haveEasterDay
     */
    public static boolean haveEasterDay()

    /**
     * Calculate Easter Sunday.
     * This algorithm holds for any year in the Gregorian Calendar,
     * which (of course) means years including and after 1583.
     * 
     * @param nYear
     *        4 digit year
     */
    public static Calendar getEasterSunday(int nYear)


  • Date/Time manipulation
   /**
     * Returns the default Locale instance used by DateUtils.
    **/
    public static Locale getDefaultLocale()

    /**
     * Returns the default TimeZone instance used by DateUtils.
    **/
    public static TimeZone getDefaultTimeZone()

    /**
     * Create a Calendar instance with default timezone.
     **/
    public static Calendar createCalendar()

    /**
     * @return the tomorrow {@link java.util.Date} object
     */
    public static Date getTomorrow()


    /**
     * Compare two date/time represented as {@link java.lang.String} in the  given format.
     * 
     * @return -1 if date1 < date2, 0 if date1 = date2, 1 if date1 > date2
     */
    public static int compare(String date1, String format1, String date2, String format2)


    /**
     * Compare two date/time represented as {@link java.lang.String} in the  given format and {@link java.util.Date}.
     * 
     * @return -1 if date1 < date2, 0 if date1 = date2, 1 if date1 > date2
     */
    public static int compare(String date1, String format1, Date date2)




    /**
     * Change the date/time represented as {@link java.lang.String} in the given format.
     * The parameters type and value must be the same of {@link java.util.Calendar}.
     * 
     * @param date the date/time to change
     * @param format the date/time conversion pattern
     * @param type the field to change
     * @param value the field value
     * @return the modified date
     */
    public static Date setTime(String date, String format, int type, int value)

    /**
     * Change the date/time represented as {@link java.util.Date}. 
     * The parameters type and value must be the same of {@link java.util.Calendar}.
     * 
     * @param date the date/time to change
     * @param type the field to change
     * @param value the field value
     * @return the modified date
     */
    public static Date setTime(Date date, int type, int value)

    /**
     * Change the date/time represented as {@link java.lang.String} in the given format. 
     * The parameters type and value must be the same of {@link java.util.Calendar}.
     * 
     * @param date
     *        the date/time to change
     * @param format
     *        the date/time conversion pattern
     * @param type
     *        the field to change
     * @param value
     *        the offset value
     * @return the modified date
     */
    public static Date addTime(String date, String format, int type, int value)

    /**
     * Change the date/time represented as {@link java.lang.String} in the given format.
     * The parameters type and value must be the same of {@link java.util.Calendar}.
     * 
     * @param date the date/time to change
     * @param format the date/time conversion pattern
     * @param type the field to change
     * @param value the offset value
     * @return the modified date
     */
    public static String addTime(String date, String format, String type, String value)

    /**
     * Change the date/time represented as {@link java.util.Date}.
     * The parameters type and value must be the same of {@link java.util.Calendar}.
     * 
     * @param date the date/time to change
     * @param type the field to change
     * @param value the offset value
     * @return the modified date
     */
    public static Date addTime(Date date, int type, int value)

    /**
     * Change the current date/time. The parameters type and
     * value must be the same of {@link java.util.Calendar}.
     * 
     * @param type the field to change
     * @param value the offset value
     * @param onlyDate
     * if true the following fields are resetted: Calendar.HOUR_OF_DAY
     *        Calendar.MINUTE Calendar.SECOND Calendar.MILLISECOND
     * @return the modified date
     */
    public static Date addTime(int type, int value, boolean onlyDate)

    /**
     * Copy the following fields of the date/time date2 to
     * date1, represented as {@link java.util.Date}:
     * Calendar.DAY_OF_MONTH Calendar.MONTH Calendar.YEAR
     * 
     * @param date1 the date/time to change
     * @param date2 the source date/time
     * @return the modified date1
     */
    public static Date copyDate(Date date1, Date date2)

    /**
     * Copy the following fields of the date/time date2 to
     * date1, represented as {@link java.util.Calendar}:
     * Calendar.DAY_OF_MONTH Calendar.MONTH Calendar.YEAR
     * 
     * @param date1 the date/time to change
     * @param date2 the source date/time
     * @return the modified date1
     */
    public static Calendar copyDate(Calendar date1, Calendar date2)

    /**
     * Copy the following fields of the date/time date2 to
     * date1, represented as {@link java.util.Date}:
     * Calendar.HOUR_OF_DAY Calendar.MINUTE Calendar.SECOND Calendar.MILLISECOND
     * 
     * @param date1 the date/time to change
     * @param date2 the source date/time
     * @return the modified date1
     */
    public static Date copyTime(Date date1, Date date2)

    /**
     * Copy the following fields of the date/time date2 to
     * date1, represented as {@link java.util.Calendar}:
     * Calendar.HOUR_OF_DAY Calendar.MINUTE Calendar.SECOND Calendar.MILLISECOND
     * 
     * @param date1 the date/time to change
     * @param date2 the source date/time
     * @return the modified date1
     */
    public static Calendar copyTime(Calendar date1, Calendar date2)

    /**
     * Reset the following fields of the date/time represented as
     * {@link java.util.Date}: Calendar.HOUR_OF_DAY Calendar.MINUTE
     * Calendar.SECOND Calendar.MILLISECOND
     * 
     * @param date the date/time to change
     * @return the modified date
     */
    public static Date resetTime(Date date)

    /**
     * Reset the following fields of the date/time represented as
     * {@link java.util.Calendar}: Calendar.HOUR_OF_DAY Calendar.MINUTE
     * Calendar.SECOND Calendar.MILLISECOND
     * 
     * @param date the date/time to change
     * @return the modified date
     */
    public static Calendar resetTime(Calendar date)

    /**
     * Reset the following fields of the date/time represented as
     * {@link java.util.Date}: Calendar.HOUR_OF_DAY Calendar.MINUTE
     * Calendar.SECOND Calendar.MILLISECOND
     * 
     * @param date the date/time to change
     * @return the modified date
     */
    public static Date setStartOfDay(Date date)

    /**
     * Reset the following fields of the date/time represented as
     * {@link java.util.Calendar}: Calendar.HOUR_OF_DAY Calendar.MINUTE
     * Calendar.SECOND Calendar.MILLISECOND
     * 
     * @param date the date/time to change
     * @return the modified date
     */
    public static Calendar setStartOfDay(Calendar date)

    /**
     * Set to their maximum, the following fields of the date/time represented
     * as {@link java.util.Date}: Calendar.HOUR_OF_DAY Calendar.MINUTE
     * Calendar.SECOND Calendar.MILLISECOND
     * 
     * @param date the date/time to change
     * @return the modified date
     */
    public static Date setEndOfDay(Date date)

    /**
     * Set to their maximum, the following fields of the date/time represented
     * as {@link java.util.Calendar}: Calendar.HOUR_OF_DAY Calendar.MINUTE
     * Calendar.SECOND Calendar.MILLISECOND
     * 
     * @param date the date/time to change
     * @return the modified date
     */
    public static Calendar setEndOfDay(Calendar date)

    /**
     * Generate a range of days starting from date1 till
     * date2, represented as {@link java.lang.String} in the given
     * format.
     * 
     * @param date1 start date (inclusive)
     * @param format1 format of start date
     * @param date2 end date (inclusive)
     * @param format2 format of end date
     * @return an array of {@link java.util.Date}
     */
    public static Date[] generateRange(String date1, String format1, String date2, String format2)

    /**
     * Generate a range of days starting from date1 till
     * date2, represented as {@link java.util.Date}.
     * 
     * @param date1 start date (inclusive)
     * @param date2 end date (inclusive)
     * @return an array of {@link java.util.Date}
     */
    public static Date[] generateRange(Date date1, Date date2)


    /**
     * Generate a range of days starting from date1 tilldate2, represented as {@link java.util.Calendar}.
     * 
     * @param date1 start date (inclusive)
     * @param date2 end date (inclusive)
     * @return an array of {@link java.util.Date}
     */
    public static Date[] generateRange(Calendar date1, Calendar date2)

    /**
     * Return the days difference as date2 - date1, represented as {@link java.util.Date}.
     * 
     * @param date1
     * @param date2
     * @param tZone
     * @return the days difference
     */
    public static DateDiff getDiff(Date date1, Date date2, TimeZone tZone)

    /**
     * Return the days difference as date2 - date1, represented as {@link java.lang.String} in the given format.
     * 
     * @param date1
     * @param format1
     * @param date2
     * @param format2
     * @param tZone
     * @return the days difference
     */
    public static DateDiff getDiff(String date1, String format1, String date2, String format2, TimeZone tZone)


    public static int numHoursInDay(Date date)

    public static int numHoursInDay(String date, String format)

    /**
     * Returns type of day: 1 = Feriale; 2 = Prefestivo; 4 = Festivo;
     * 
     * @param today
     * @return
     */
    public static int checkDay(Date day) throws IllegalStateException

    public static int checkDay(String data, String format)

    public static boolean checkDayType(int dayType, Date day) throws IllegalStateException