|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.opensymphony.util.DateUtil
public class DateUtil
This class is used to convert Dates to ISO 8601 formatted dates and back. This class is an implementation of the ISO 8601 International Date Format standard. The ISO 8601 helps to alleviate the following problem:
Ever been to a webpage to see that the time-sensitive information you are interested in is dated 03/05/01?
Is this date the 3rd of May 2001 or the 5th of March 2001 or the 1st of May 2003 and does the 01 refer to 2001 in the first two cases?
In order to make the right choice, you must ask yourself some questions :
The Internet is a truly International method of communicating - there are no political or cultural boundaries drawn on the www page you call up - the page could have been stored in the Smithsonian Institute or on a small server in a basement in Ulan Bator, Mongolia. Often, you have no way of telling. So, if anyone in the world can read your page, why not ensure that any date references on that page can be read correctly and unambiguously by that person, by using the ISO 8601:1988 International Date Format?
The basic format is: "CCYYMMDDThhmmsssss±nnn"
Characters used in place of digits or signs | |
---|---|
[Y] | represents a digit used in the time element year |
[M] | represents a digit used in the time element month |
[D] | represents a digit used in the time element day |
[T] | place holder denoting time |
[h] | represents a digit used in the time element hour |
[m] | represents a digit used in the time element minute |
[s] | represents a digit used in the time element second |
[n] | represents digit(s), constituting a positive integer or zero |
[±] | represents a plus sign [+] if in combination with the following element a positive value or zero needs to be represented, or a minus sign [] if in combination with the following element a negative value needs to be represented. |
The expanded format includes formating: "CCYY-MM-DDThh:mm:ss,sss±nnn"
Further there are some date math functions for ISO Dates.
funtions for julian dates
Field Summary | |
---|---|
static DateFormatSymbols |
dateFormatSymbles
|
static String |
ISO_DATE_FORMAT
Base ISO 8601 Date format yyyyMMdd i.e., 20021225 for the 25th day of December in the year 2002 |
static String |
ISO_DATE_TIME_FORMAT
Base ISO 8601 Date format yyyyMMddTHHmmssSSSzzz i.e., 20021225T143212333-500 for the 25th day of December in the year 2002 at 2 pm 32 min 12 secs 333 mills -5 hours from GMT |
static String |
ISO_EXPANDED_DATE_FORMAT
Expanded ISO 8601 Date format yyyy-MM-dd i.e., 2002-12-25 for the 25th day of December in the year 2002 |
static String |
ISO_EXPANDED_DATE_TIME_FORMAT
Base ISO 8601 Date format yyyy-MM-ddTHH:mm:ss,SSSzzz i.e., 2002-12-25T14:32:12,333-500 for the 25th day of December in the year 2002 at 2 pm 32 min 12 secs 333 mills -5 hours from GMT |
static String |
ISO_EXPANDED_TIME_FORMAT
Basic ISO 8601 Time format HH:mm:ss,SSSzzz i.e., 14:32:12,333-500 for 2 pm 32 min 12 secs 333 mills -5 hours from GMT 24 hour clock |
static String |
ISO_TIME_FORMAT
Basic ISO 8601 Time format HHmmssSSSzzz i.e., 143212333-500 for 2 pm 32 min 12 secs 333 mills -5 hours from GMT 24 hour clock |
Constructor Summary | |
---|---|
DateUtil()
|
Method Summary | |
---|---|
static String |
add(String isoString,
int field,
int amount)
Date Arithmetic function. |
static String |
add(String isoString,
int field,
int amount,
boolean expanded)
Date Arithmetic function. |
static String |
dateToISO(Date date)
non-expanded |
static String |
dateToISO(Date date,
boolean expanded)
Return an ISO date string |
static long |
dateToJulianDay(Date date)
Converts java Date to Julian day count A Julian day is defined as the number of days since Jan 1, 1. |
static int |
daysBetween(Calendar early,
Calendar late)
Deprecated. |
static int |
daysBetween(Date early,
Date late)
Deprecated. |
static long |
daysBetween(String isoEarly,
String isoLate,
boolean expanded)
Returns the days between two dates. |
static TimeZone |
getTimeZoneFromDateTime(String date)
|
static TimeZone |
getTimeZoneFromDateTime(String date,
boolean expanded)
|
static boolean |
isLeapYear(String isoString)
|
static boolean |
isLeapYear(String isoString,
boolean expanded)
|
static Date |
isoToDate(String dateString)
non-expanded |
static Date |
isoToDate(String dateString,
boolean expanded)
Return an ISO date string as a java.util.Date |
static Date |
isoToSQLDate(String dateString)
non-expanded |
static Date |
isoToSQLDate(String dateString,
boolean expanded)
Return an ISO date string as a java.sql.Date |
static Time |
isoToTime(String dateString)
non-expanded |
static Time |
isoToTime(String dateString,
boolean expanded)
|
static Timestamp |
isoToTimestamp(String dateString)
non-expanded |
static Timestamp |
isoToTimestamp(String dateString,
boolean expanded)
|
static Date |
julianDayCountToDate(long julian)
Convert a julian day count to a java sql Date @ midnight |
static Date |
julianDayToDate(long julian)
Convert a julian day count to a java util Date @ midnight |
static long |
julianDayToMillis(long julian)
Converts Julian day to time as milliseconds. |
static long |
millisToJulianDay(long millis)
Converts time as milliseconds to Julian day count A Julian day is defined as the number of days since Jan 1, 1. |
protected static float |
normalizedJulian(float JD)
|
static String |
roll(String isoString,
int field,
boolean up)
Time Field Rolling function. |
static String |
roll(String isoString,
int field,
boolean up,
boolean expanded)
Time Field Rolling function. |
static String |
timestampToISO(Timestamp date)
non-expanded |
static String |
timestampToISO(Timestamp date,
boolean expanded)
|
static String |
timeToISO(Time date)
non-expanded |
static String |
timeToISO(Time date,
boolean expanded)
|
static Date |
toDate(float JD)
Deprecated. |
static float |
toJulian(Calendar c)
Return a Julian date based on the input parameter. |
static float |
toJulian(Date date)
Return a Julian date based on the input parameter. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final String ISO_DATE_FORMAT
public static final String ISO_EXPANDED_DATE_FORMAT
public static final String ISO_TIME_FORMAT
public static final String ISO_EXPANDED_TIME_FORMAT
public static final String ISO_DATE_TIME_FORMAT
public static final String ISO_EXPANDED_DATE_TIME_FORMAT
public static final DateFormatSymbols dateFormatSymbles
Constructor Detail |
---|
public DateUtil()
Method Detail |
---|
public static final boolean isLeapYear(String isoString, boolean expanded) throws ParseException
isoString
- expanded
-
ParseException
public static final boolean isLeapYear(String isoString) throws ParseException
isoString
-
ParseException
public static final TimeZone getTimeZoneFromDateTime(String date, boolean expanded) throws ParseException
ParseException
public static final TimeZone getTimeZoneFromDateTime(String date) throws ParseException
ParseException
public static final String add(String isoString, int field, int amount, boolean expanded) throws ParseException
isoString
- field
- amount
- expanded
- use formating char's
ParseException
public static final String add(String isoString, int field, int amount) throws ParseException
isoString
- field
- amount
-
ParseException
public static final String dateToISO(Date date, boolean expanded)
date
- expanded
- use formating char's
public static final String dateToISO(Date date)
date
-
public static final long dateToJulianDay(Date date)
date
-
public static final int daysBetween(Date early, Date late)
early
- the "first date"late
- the "second date"
public static final int daysBetween(Calendar early, Calendar late)
early
- late
-
public static final long daysBetween(String isoEarly, String isoLate, boolean expanded) throws ParseException
isoEarly
- the "first date" in ISO DateTime FormatisoLate
- the "second date" in ISO Date Time format
ParseException
public static final Date isoToDate(String dateString, boolean expanded) throws ParseException
dateString
- expanded
- use formating charaters
ParseException
public static final Date isoToDate(String dateString) throws ParseException
dateString
-
ParseException
public static final Date isoToSQLDate(String dateString, boolean expanded) throws ParseException
dateString
- expanded
- expanded use formating charaters
ParseException
public static final Date isoToSQLDate(String dateString) throws ParseException
dateString
-
ParseException
public static final Time isoToTime(String dateString, boolean expanded) throws ParseException
expanded
- expanded use formating charatersdateString
-
ParseException
public static final Time isoToTime(String dateString) throws ParseException
dateString
-
ParseException
public static final Timestamp isoToTimestamp(String dateString, boolean expanded) throws ParseException
expanded
- expanded use formating charatersdateString
-
ParseException
public static final Timestamp isoToTimestamp(String dateString) throws ParseException
dateString
-
ParseException
public static final Date julianDayCountToDate(long julian)
julian
- the given Julian day number.
public static final Date julianDayToDate(long julian)
julian
- the given Julian day number.
public static final long julianDayToMillis(long julian)
julian
- the given Julian day number.
public static final long millisToJulianDay(long millis)
millis
- the given milliseconds.
public static final String roll(String isoString, int field, boolean up, boolean expanded) throws ParseException
isoString
- field
- the time field.up
- Indicates if rolling up or rolling down the field value.expanded
- use formating char's
ParseException
- if an unknown field value is given.public static final String roll(String isoString, int field, boolean up) throws ParseException
isoString
- field
- the time field.up
- Indicates if rolling up or rolling down the field value.
ParseException
- if an unknown field value is given.public static final String timeToISO(Time date, boolean expanded)
expanded
- expanded use formating charatersdate
-
public static final String timeToISO(Time date)
date
-
public static final String timestampToISO(Timestamp date, boolean expanded)
expanded
- expanded use formating charatersdate
-
public static final String timestampToISO(Timestamp date)
date
-
public static final Date toDate(float JD)
JD
- the Julian date
public static final float toJulian(Calendar c)
c
- a calendar instance
public static final float toJulian(Date date)
date
-
protected static final float normalizedJulian(float JD)
|
OSCore Project Page | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |