LEONARDI Application Composer - 8.9.0.40 by W4 S.A.

leon.misc
Class LyDateFormatter

java.lang.Object
  extended by leon.misc.LyDateFormatter

public final class LyDateFormatter
extends java.lang.Object

This class implements some static methods to format and parse dates using a particular date format. Format passed to these methods must use :

Date formats examples: MM/dd/yyyy hh:mm:ss or dd/MM/yy or dd/MM/yyyy HH:mm.


Field Summary
static java.lang.String __VERSION
           
static java.text.DateFormat _internalDateFormat
          Internal date format to save ids, or peer values
 
Constructor Summary
LyDateFormatter()
           
 
Method Summary
static java.util.Date buildDate(int year, int month, int date, int hrs, int min, int sec)
          Allocates a Date object and initializes it so that it represents the instant at the start of the second specified by the year, month, date, hrs, min, and sec arguments, in the local time zone.
static java.util.Date buildDate(long dateInMillis, java.lang.String format)
          Allocates a Date object that represents the given date in milliseconds.
static java.lang.String checkDate(java.lang.String val, java.text.DateFormat dateFormat)
          Checks whether the given date string is correct according to format.
static java.lang.String format(java.util.Date date, java.text.DateFormat format, LyEnvironment env)
          Formats a date with the given format.
static java.lang.String format(java.util.Date date, java.text.DateFormat format, LyEnvironment env, java.lang.String timeZone)
          Formats a date with the given format.
static java.lang.String format(java.util.Date date, java.lang.String format)
          Formats a date with the given format.
static java.lang.String format(java.util.Date date, java.lang.String format, LyEnvironment env)
          Formats a date with the given format.
static java.util.Date fromString(java.lang.String dateString)
          Parses a string to retrieve a date from the Date.toString() method.
static int getAge(java.util.Date date)
          Utility method that returns the age from a given date.
static int getDate(java.util.Date date)
          Gets the day of the month represented by the specified Date object.
static int getDay(java.util.Date date)
          Gets the day of the week represented by the specified date.
static int getDayOfYear(java.util.Date date)
          Gets the day of the year represented by the specified Date object.
static int getHours(java.util.Date date)
          Gets the hour represented by the specified Date object.
static java.text.DateFormat getInternalDateFormat()
          Internal date format to save ids, or peer values
static int getMinutes(java.util.Date date)
          Gets the number of minutes past the hour represented by the specified date, as interpreted in the local time zone.
static int getMonth(java.util.Date date)
          Gets a number representing the month that contains (or begins with) the instant in time represented by the specified Date object.
static double getRealAge(java.util.Date date)
          Utility method that returns the age from a given date as a float.
static int getSeconds(java.util.Date date)
          Gets the number of seconds past the minute represented by the specified date.
static int getYear(java.util.Date date)
          Gets a value that is the result of subtracting 1900 from the year that contains (or begins with) the instant in time represented by the specifie Date object, as interpreted in the local time zone.
static java.util.Date parse(java.lang.String dateString, java.lang.String format)
          Parses a string to retrieve a date with the given format.
static java.util.Date parse(java.lang.String dateString, java.lang.String format, LyEnvironment env)
          Parses a string to retrieve a date with the given format.
static java.util.Date parse(java.lang.String dateString, java.lang.String format, LyEnvironment env, java.lang.String timeZone)
          Parses a string to retrieve a date with the given format.
static java.util.Date setDate(java.util.Date date, int d)
          Sets the day of the month of the specified Date object to the specified value.
static java.util.Date setDayOfYear(java.util.Date date, int d)
          Sets the day of the year of the specified Date object to the specified value.
static java.util.Date setHours(java.util.Date date, int h)
          Sets the hour of the Date object to the specified value.
static void setInternalDateFormat(java.lang.String format)
          Internal date format to save ids, or peer values
static java.util.Date setMinutes(java.util.Date date, int m)
          Sets the minutes of the Date object to the specified value.
static java.util.Date setMonth(java.util.Date date, int m)
          Sets the month of the date to the specified value.
static java.util.Date setSeconds(java.util.Date date, int s)
          Sets the seconds of the Date to the specified value.
static java.util.Date setYear(java.util.Date date, int y)
          Sets the year of the Date object to be the specified value plus 1900.
static java.lang.String toString(java.util.Date date)
          Parses a string to retrieve a date from the Date.toString() method.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

__VERSION

public static final java.lang.String __VERSION
See Also:
Constant Field Values

_internalDateFormat

public static java.text.DateFormat _internalDateFormat
Internal date format to save ids, or peer values

Constructor Detail

LyDateFormatter

public LyDateFormatter()
Method Detail

format

public static java.lang.String format(java.util.Date date,
                                      java.text.DateFormat format,
                                      LyEnvironment env,
                                      java.lang.String timeZone)
Formats a date with the given format.

Parameters:
date - The date that must be formatted.
format - The format of the result.
env - Current environment (used to retrieve current date locale).
timeZone - the time zone to use
Returns:
A string that represents the formatted date.

format

public static java.lang.String format(java.util.Date date,
                                      java.text.DateFormat format,
                                      LyEnvironment env)
Formats a date with the given format.

Parameters:
date - The date that must be formatted.
format - The format of the result.
env - Current environment (used to retrieve current date locale).
Returns:
A string that represents the formatted date.

format

public static java.lang.String format(java.util.Date date,
                                      java.lang.String format)
Formats a date with the given format.

Parameters:
date - The date that must be formatted.
format - The format of the result.
Returns:
A string that represents the formatted date.

format

public static java.lang.String format(java.util.Date date,
                                      java.lang.String format,
                                      LyEnvironment env)
Formats a date with the given format.

Parameters:
date - The date that must be formatted.
format - The format of the result.
env - Current environment (used to retrieve current date locale).
Returns:
A string that represents the formatted date.

parse

public static java.util.Date parse(java.lang.String dateString,
                                   java.lang.String format)
Parses a string to retrieve a date with the given format.

Parameters:
dateString - The string that must be parsed.
format - The format of the string.
Returns:
A Date that represents the parsed string.

parse

public static java.util.Date parse(java.lang.String dateString,
                                   java.lang.String format,
                                   LyEnvironment env)
Parses a string to retrieve a date with the given format.

Parameters:
dateString - The string that must be parsed.
format - The format of the string.
env - Current environment (used to retrieve current date locale).
Returns:
A Date that represents the parsed string.

parse

public static java.util.Date parse(java.lang.String dateString,
                                   java.lang.String format,
                                   LyEnvironment env,
                                   java.lang.String timeZone)
Parses a string to retrieve a date with the given format.

Parameters:
dateString - The string that must be parsed.
format - The format of the string.
env - Current environment (used to retrieve current date locale).
timeZone - The time zone to use
Returns:
A Date that represents the parsed string.

fromString

public static java.util.Date fromString(java.lang.String dateString)
Parses a string to retrieve a date from the Date.toString() method. In all cases, we must have : dateA equals fromString(dateA.toString())

Parameters:
dateString - The string that must be parsed.
Returns:
A Date that represents the parsed string.

toString

public static java.lang.String toString(java.util.Date date)
Parses a string to retrieve a date from the Date.toString() method. In all cases, we must have : dateA equals fromString(dateA.toString())

Parameters:
dateString - The string that must be parsed.
Returns:
A Date that represents the parsed string.

getDate

public static int getDate(java.util.Date date)
Gets the day of the month represented by the specified Date object. The returned value is between 1 and 31 and represents day of the month that contains (or begins with) the given Date time, as interpreted in the local time zone.

Parameters:
date - the date
Returns:
the day of the month represented by the specified date.

getDay

public static int getDay(java.util.Date date)
Gets the day of the week represented by the specified date.
Possible returned values are:

Those values represent the day of the week that contains (or begins with) the instant in time represented by the Date object, as interpreted in the local time zone.

Parameters:
date - the date
Returns:
the day of the week represented by this date.

getHours

public static int getHours(java.util.Date date)
Gets the hour represented by the specified Date object. The returned value is a number (0 through 23) representing the hour within the day that contains (or begins with) the instant in time represented by the Date object, as interpreted in the local time zone.

Parameters:
date - the date
Returns:
the hour represented by this date.

getMinutes

public static int getMinutes(java.util.Date date)
Gets the number of minutes past the hour represented by the specified date, as interpreted in the local time zone. The value returned is between 0 and 59.

Parameters:
date - the date
Returns:
the number of minutes past the hour represented by this date.

getMonth

public static int getMonth(java.util.Date date)
Gets a number representing the month that contains (or begins with) the instant in time represented by the specified Date object. The value returned is between 0 and 11, with the value 0 representing January.

Parameters:
date - the date
Returns:
the month represented by this date.

getSeconds

public static int getSeconds(java.util.Date date)
Gets the number of seconds past the minute represented by the specified date. The value returned is between 0 and 61. The values 60 and 61 can only occur on those Java Virtual Machines that take leap seconds into account.

Parameters:
date - the date
Returns:
the number of seconds past the minute represented by this date.

getYear

public static int getYear(java.util.Date date)
Gets a value that is the result of subtracting 1900 from the year that contains (or begins with) the instant in time represented by the specifie Date object, as interpreted in the local time zone.

Parameters:
date - the date
Returns:
the year represented by this date, minus 1900.

setDate

public static java.util.Date setDate(java.util.Date date,
                                     int d)
Sets the day of the month of the specified Date object to the specified value. This Date object is modified so that it represents a point in time within the specified day of the month, with the year, month, hour, minute, and second the same as before, as interpreted in the local time zone. If the date was April 30, for example, and the date is set to 31, then it will be treated as if it were on May 1, because April has only 30 days.

Parameters:
date - the date to modify
d - the day of the month value between 1-31.
Returns:
the new date object

setHours

public static java.util.Date setHours(java.util.Date date,
                                      int h)
Sets the hour of the Date object to the specified value. The Date object is modified so that it represents a point in time within the specified hour of the day, with the year, month, date, minute, and second the same as before, as interpreted in the local time zone.

Parameters:
date - the date to modify
h - the hour value.
Returns:
the new date object

setMinutes

public static java.util.Date setMinutes(java.util.Date date,
                                        int m)
Sets the minutes of the Date object to the specified value. The Date object is modified so that it represents a point in time within the specified minute of the hour, with the year, month, date, hour, and second the same as before, as interpreted in the local time zone.

Parameters:
date - the date to modify
m - the value of the minutes.
Returns:
the new date object

setMonth

public static java.util.Date setMonth(java.util.Date date,
                                      int m)
Sets the month of the date to the specified value. The Date object is modified so that it represents a point in time within the specified month, with the year, date, hour, minute, and second the same as before, as interpreted in the local time zone. If the date was October 31, for example, and the month is set to June, then the new date will be treated as if it were on July 1, because June has only 30 days.

Parameters:
date - the date to modify
m - the month value between 0-11.
Returns:
the new date object

setSeconds

public static java.util.Date setSeconds(java.util.Date date,
                                        int s)
Sets the seconds of the Date to the specified value. The Date object is modified so that it represents a point in time within the specified second of the minute, with the year, month, date, hour, and minute the same as before, as interpreted in the local time zone.

Parameters:
date - the date to modify
s - the seconds value.
Returns:
the new date object

setYear

public static java.util.Date setYear(java.util.Date date,
                                     int y)
Sets the year of the Date object to be the specified value plus 1900. The Date object is modified so that it represents a point in time within the specified year, with the month, date, hour, minute, and second the same as before, as interpreted in the local time zone. (Of course, if the date was February 29, for example, and the year is set to a non-leap year, then the new date will be treated as if it were on March 1.)

Parameters:
date - the date to modify
y - the year value.
Returns:
the new date object

buildDate

public static java.util.Date buildDate(long dateInMillis,
                                       java.lang.String format)
Allocates a Date object that represents the given date in milliseconds.

Parameters:
dateInMillis - the date as a long.
Returns:
the new date object

buildDate

public static java.util.Date buildDate(int year,
                                       int month,
                                       int date,
                                       int hrs,
                                       int min,
                                       int sec)
Allocates a Date object and initializes it so that it represents the instant at the start of the second specified by the year, month, date, hrs, min, and sec arguments, in the local time zone.

Parameters:
year - the year minus 1900.
month - the month between 0-11.
date - the day of the month between 1-31.
hrs - the hours between 0-23.
min - the minutes between 0-59.
sec - the seconds between 0-59.
Returns:
the new date object

checkDate

public static java.lang.String checkDate(java.lang.String val,
                                         java.text.DateFormat dateFormat)
Checks whether the given date string is correct according to format.

Parameters:
val - date string
dateFormat - date format
Returns:
The corrected date string, or null if the given string is not correct.

getDayOfYear

public static int getDayOfYear(java.util.Date date)
Gets the day of the year represented by the specified Date object. The returned value is between 1 and 366 and represents day of the year.

Parameters:
date - the date
Returns:
the day of the year represented by the specified date.

setDayOfYear

public static java.util.Date setDayOfYear(java.util.Date date,
                                          int d)
Sets the day of the year of the specified Date object to the specified value. This Date object is modified so that it represents a point in time at the specified day. *

Parameters:
date - the date to modify
d - the day of the year value between 0-366.
Returns:
the new date object

setInternalDateFormat

public static void setInternalDateFormat(java.lang.String format)
Internal date format to save ids, or peer values

Parameters:
format -

getInternalDateFormat

public static java.text.DateFormat getInternalDateFormat()
Internal date format to save ids, or peer values

Returns:
the formatter

getAge

public static int getAge(java.util.Date date)
Utility method that returns the age from a given date.

Parameters:
date - The date from which the age is requested.
Returns:
The age corresponding to the date.

getRealAge

public static double getRealAge(java.util.Date date)
Utility method that returns the age from a given date as a float.

Parameters:
date - The date from which the age is requested.
Returns:
The age corresponding to the date.

(c) January 2013 - W4 S.A.

Website: W4 S.A., contact us: support@w4global.com