com.jfw.util
Class DateUtils

java.lang.Object
  extended by com.jfw.util.DateUtils

public final class DateUtils
extends java.lang.Object

Date utils methods. All methods are static and thread safe.


Constructor Summary
DateUtils()
           
 
Method Summary
static int[] elapsed(java.util.GregorianCalendar g1, java.util.GregorianCalendar g2)
          Calculate the difference between to dates.
static java.lang.String format(java.lang.String toChange)
          Change a date String in format "yyyy-mm-dd" in format "dd/mm/yyyy".
static java.lang.String format(java.lang.String toChange, java.lang.String format)
          Change a date String in format "dd/mm/yyyy" in format specified in parameter format.
static java.lang.String format4DB(java.lang.String toChange)
          Change a String from format "dd/mm/yyyy" to format "yyyymmdd".
static java.lang.String formatAddLeadingZero(java.lang.String toChange)
          Change a String from format "d/m/yyyy" adding leading zeros for day and month.
static java.lang.String fromDateToString(java.util.Date date)
          Change an java.util.Date in a String with format "dd-mm-yyyy".
static java.lang.String fromDateToString(java.sql.Date date)
          Change an java.sql.Date in a String with format "dd-mm-yyyy".
static java.lang.String fromDateToString(java.util.Date date, java.lang.String format)
          Change an java.util.Date in a String with format the format specified in parameter format.
static java.lang.String fromDateToString(java.sql.Date date, java.lang.String format)
          Change an java.util.Date in a String with format the format specified in parameter format.
static java.lang.String getDateAndTime()
          Return a string with the current date and time.
static java.lang.String getDateString(java.util.GregorianCalendar gregorian)
          Get a String in format "dd/mm/yyyy".
static java.lang.String getDayFromDate(java.lang.String date)
          Get day from a String in format "mm/dd/yyyy".
static java.lang.String getDayFromDateUS(java.lang.String date)
          Get day from a String in format "yyyy-mm-dd".
static java.util.GregorianCalendar getGregorianCalendar()
          Return the java.util.GregorianCalendar for time zone CET.
static java.util.GregorianCalendar getGregorianCalendar(java.lang.String dateString)
          Return the java.util.GregorianCalendar of the date specified in parameter dateString.
static java.util.GregorianCalendar getGregorianCalendar(java.lang.String dateString, java.lang.String separator)
          Return the java.util.GregorianCalendar of the date specified in parameter dateString.
static java.lang.String getHoursFromDateTime(java.lang.String dateTime)
          Get hours from a String in format "date_in various_format mm:hh"
static java.lang.String getMinutesFromDateTime(java.lang.String dateTime)
          Get minutes from a String in format "date_in various_format mm:hh"
static java.lang.String getMonth(java.util.GregorianCalendar gregorian)
          Return the month of year as a String from 1 to 12.
static java.lang.String getMonthDay(java.util.GregorianCalendar gregorian)
          Return the day of month.
static java.lang.String getMonthDay(java.util.GregorianCalendar gregorian, boolean leadingZero)
          Return the day of month adding a 0 at start if needed.
static java.lang.String getMonthFromDate(java.lang.String date)
          Get month from a String in format "mm/dd/yyyy".
static java.lang.String getMonthFromDateUS(java.lang.String date)
          Get month from a String in format "yyyy-mm-dd".
static java.lang.String getMSecondsFromDateTime(java.lang.String dateTime)
          Get mseconds from a String in format "date_in various_format mm:hh:ss.ms"
static java.lang.String getSecondsFromDateTime(java.lang.String dateTime)
          Get seconds from a String in format "date_in various_format mm:hh:ss"
static java.lang.String getTimeExtension()
          Get a string with format .YYYY-MM-DD.HH-MM-SS.
static java.lang.String getTimeExtension(long date)
          Get a string with format .YYYY-MM-DD.HH-MM-SS.
static java.lang.String getWeekDay(java.util.GregorianCalendar gregorian)
          Return the day of week.
static java.lang.String getYear(java.util.GregorianCalendar gregorian)
          Return the year.
static java.lang.String getYearFromDate(java.lang.String date)
          Get year from a String in format "mm/dd/yyyy".
static java.lang.String getYearFromDateUS(java.lang.String date)
          Get year from a String in format "yyyy-mm-dd".
static java.lang.String[] transformDate(java.lang.String dateTime)
          Get a formated string reppresentation of Date.getTime() string value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DateUtils

public DateUtils()
Method Detail

fromDateToString

public static java.lang.String fromDateToString(java.util.Date date)
Change an java.util.Date in a String with format "dd-mm-yyyy".

Parameters:
date - the java.util.Date to format
Returns:
String in format "dd-mm-yyyy"

fromDateToString

public static java.lang.String fromDateToString(java.sql.Date date)
Change an java.sql.Date in a String with format "dd-mm-yyyy".

Parameters:
date - the java.sql.Date to format
Returns:
String in format "dd-mm-yyyy"

fromDateToString

public static java.lang.String fromDateToString(java.util.Date date,
                                                java.lang.String format)
Change an java.util.Date in a String with format the format specified in parameter format.

Parameters:
date - the java.util.Date to format
format - the format to use
Returns:
String in the specified format

fromDateToString

public static java.lang.String fromDateToString(java.sql.Date date,
                                                java.lang.String format)
Change an java.util.Date in a String with format the format specified in parameter format.

Parameters:
date - the java.sql.Date to format
format - the format to use
Returns:
String in the specified format

format

public static java.lang.String format(java.lang.String toChange,
                                      java.lang.String format)
Change a date String in format "dd/mm/yyyy" in format specified in parameter format.

Parameters:
toChange - the String to format
format - the format to use
Returns:
String in the specified format

format

public static java.lang.String format(java.lang.String toChange)
Change a date String in format "yyyy-mm-dd" in format "dd/mm/yyyy".

Parameters:
toChange - the String to format
Returns:
String in format "dd/mm/yyyy"

format4DB

public static java.lang.String format4DB(java.lang.String toChange)
Change a String from format "dd/mm/yyyy" to format "yyyymmdd".

Parameters:
toChange - Stringa in format "dd/mm/yyyy" to change
Returns:
Stringa in format "yyyymmdd"

formatAddLeadingZero

public static java.lang.String formatAddLeadingZero(java.lang.String toChange)
Change a String from format "d/m/yyyy" adding leading zeros for day and month.

Parameters:
toChange - Stringa in format "d/m/yyyy" to change
Returns:
Stringa in format "dd/mm/yyyy"

getDateString

public static java.lang.String getDateString(java.util.GregorianCalendar gregorian)
Get a String in format "dd/mm/yyyy".

Parameters:
gregorian - the java.util.GregorianCalendar to use
Returns:
String in format "dd/mm/yyyy"

getGregorianCalendar

public static java.util.GregorianCalendar getGregorianCalendar(java.lang.String dateString)
Return the java.util.GregorianCalendar of the date specified in parameter dateString.

Parameters:
dateString - String in format "dd/mm/yyyy".
Returns:
a java.util.GregorianCalendar object

getGregorianCalendar

public static java.util.GregorianCalendar getGregorianCalendar(java.lang.String dateString,
                                                               java.lang.String separator)
Return the java.util.GregorianCalendar of the date specified in parameter dateString.

Parameters:
dateString - a String in format "dd$mm$yyyy"
separator - the separator for the dateString parameter ($)
Returns:
a java.util.GregorianCalendar object

getGregorianCalendar

public static java.util.GregorianCalendar getGregorianCalendar()
Return the java.util.GregorianCalendar for time zone CET.

Returns:
a java.util.GregorianCalendar object

getMonthDay

public static java.lang.String getMonthDay(java.util.GregorianCalendar gregorian)
Return the day of month.

Parameters:
gregorian - java.util.GregorianCalendar object
Returns:
the day of month

getMonthDay

public static java.lang.String getMonthDay(java.util.GregorianCalendar gregorian,
                                           boolean leadingZero)
Return the day of month adding a 0 at start if needed.

Parameters:
gregorian - java.util.GregorianCalendar object
leadingZero - if true a leading zero add when need
Returns:
the day of month with leading sero.

getWeekDay

public static java.lang.String getWeekDay(java.util.GregorianCalendar gregorian)
Return the day of week.

Parameters:
gregorian - a java.util.GregorianCalendar object
Returns:
the day of week

getMonth

public static java.lang.String getMonth(java.util.GregorianCalendar gregorian)
Return the month of year as a String from 1 to 12.

Parameters:
gregorian - a java.util.GregorianCalendar object
Returns:
month of year

getYear

public static java.lang.String getYear(java.util.GregorianCalendar gregorian)
Return the year.

Parameters:
gregorian - a java.util.GregorianCalendar object
Returns:
the year

getDayFromDateUS

public static java.lang.String getDayFromDateUS(java.lang.String date)
Get day from a String in format "yyyy-mm-dd".

Parameters:
date - String in format "yyyy-mm-dd" to use
Returns:
the day

getMonthFromDateUS

public static java.lang.String getMonthFromDateUS(java.lang.String date)
Get month from a String in format "yyyy-mm-dd".

Parameters:
date - String in format "yyyy-mm-dd" to use
Returns:
the month

getYearFromDateUS

public static java.lang.String getYearFromDateUS(java.lang.String date)
Get year from a String in format "yyyy-mm-dd".

Parameters:
date - String in format "yyyy-mm-dd" to use
Returns:
the year

getDayFromDate

public static java.lang.String getDayFromDate(java.lang.String date)
Get day from a String in format "mm/dd/yyyy".

Parameters:
date - String in format "mm/dd/yyyy" to use
Returns:
the day

getMonthFromDate

public static java.lang.String getMonthFromDate(java.lang.String date)
Get month from a String in format "mm/dd/yyyy".

Parameters:
date - String in format "mm/dd/yyyy" to use
Returns:
the month

getYearFromDate

public static java.lang.String getYearFromDate(java.lang.String date)
Get year from a String in format "mm/dd/yyyy".

Parameters:
date - String in format "mm/dd/yyyy" to use
Returns:
the year

getHoursFromDateTime

public static java.lang.String getHoursFromDateTime(java.lang.String dateTime)
Get hours from a String in format "date_in various_format mm:hh"

Parameters:
dateTime - String in format "date_in various_format mm:hh" to use
Returns:
a String in format "hh"

getMinutesFromDateTime

public static java.lang.String getMinutesFromDateTime(java.lang.String dateTime)
Get minutes from a String in format "date_in various_format mm:hh"

Parameters:
dateTime - String in format "date_in various_format mm:hh" to use
Returns:
a String in format "mm";

getSecondsFromDateTime

public static java.lang.String getSecondsFromDateTime(java.lang.String dateTime)
Get seconds from a String in format "date_in various_format mm:hh:ss"

Parameters:
dateTime - String in format "date_in various_format mm:hh:ss" to use
Returns:
a String in format "ss";

getMSecondsFromDateTime

public static java.lang.String getMSecondsFromDateTime(java.lang.String dateTime)
Get mseconds from a String in format "date_in various_format mm:hh:ss.ms"

Parameters:
dateTime - String in format "date_in various_format mm:hh:ss.ms" to use
Returns:
a String in format "ms";

elapsed

public static int[] elapsed(java.util.GregorianCalendar g1,
                            java.util.GregorianCalendar g2)
Calculate the difference between to dates.

Parameters:
g1 - a java.util.GregorianCalendar object.
g2 - a java.util.GregorianCalendar object.
Returns:
an array of int where:
  1. index 0: days diff
  2. index 1: months diff
  3. index 2: years diff
  4. index 3: 0 if parameter g1 >= g2, 1 in other case

getTimeExtension

public static final java.lang.String getTimeExtension()
Get a string with format .YYYY-MM-DD.HH-MM-SS. The actuale date and time is used.

Returns:
a string with format .YYYY-MM-DD.HH-MM-SS.

getTimeExtension

public static final java.lang.String getTimeExtension(long date)
Get a string with format .YYYY-MM-DD.HH-MM-SS. The date and time of date is used.

Parameters:
date - a Date.getTime() value.
Returns:
a string with format .YYYY-MM-DD.HH-MM-SS.

transformDate

public static java.lang.String[] transformDate(java.lang.String dateTime)
Get a formated string reppresentation of Date.getTime() string value.

Parameters:
dateTime - string value of Date.getTime().
Returns:
index 0 contains a string HH:MM:SS, index 1 contains a string YYYY-MM-DD.

getDateAndTime

public static java.lang.String getDateAndTime()
Return a string with the current date and time.

Returns:
a string with format YYYY-MM-DD HH:MM:SS,MS