Package ucar.unidata.util
Class DateUtil
java.lang.Object
ucar.unidata.util.DateUtil
A set of date oriented utilities
- Since:
- May 4, 2007 1:01:53 PM
- Author:
- edavis and the IDV development team
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final String[]A set of date formatsstatic final String[]a set of regular expressions that go along with the below DATE_FORMATSstatic final longmilliseconds in a millisecondstatic final longmilliseconds in a century (approximately)static final longmilliseconds in a daystatic final longmilliseconds in a decade (approximately)static final longmilliseconds in an hourstatic final longmilliseconds in a century (approximately)static final longmilliseconds in a minutestatic final longmilliseconds in a month (approximately)static final longmilliseconds in a secondstatic final longmilliseconds in a weekstatic final longmilliseconds in a year (approximately)static final String[]_more_static final TimeZonetimezonestatic final TimeZone_more_ -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic longdaysToMillis(double days) utility to convert a given number of days to millisecondsstatic DatedecodeWMODate(String wmoDate, Date baseDate) Decode a date from a WMO header of the form ddHHmm.static SimpleDateFormatfindFormatter(String dateString) This finds the SDF to use for the given date stringstatic Stringformat current timestatic Date[]getDateRange(String fromDate, String toDate, Date dflt) This gets a date range based on the text dates.static doublegetDateTimeRangeInHours(ucar.visad.data.CalendarDateTime fromDate, ucar.visad.data.CalendarDateTime toDate) This is calculated the hour difference between two calendardatetimesstatic SimpleDateFormat[]_more_static DategetRelativeDate(Date from, String relativeTimeString) Get a new date relative to the given date.static StringgetTimeAsISO8601(long time) format timestatic StringgetTimeAsISO8601(Date date) format timestatic longhoursToMillis(double hour) utility to convert a given number of hours to millisecondsstatic voidmainstatic DateGet the maximum of the 2 datesstatic doublemillisToHours(double millis) _more_static doublemillisToMinutes(double millis) utility to convert a given number of milliseconds to minutesstatic DateGet the minimum of the 2 datesstatic longminutesToMillis(double minutes) utility to convert a given number of minutes to millisecondsstatic DateParse the date stringstatic DateparseRelative(Date baseDate, String s, int roundDays) parse the date string (s) (e.g., -1 hour) that is relative to the given baseDatestatic longparseRelativeTimeString(String relativeTimeString) Return the delta number of milliseconds specified in the relative time stringstatic DateroundByDay(Date dttm, int day) Rounds up or down (if negative) the number of days.static double[]parse the array of date strings and returns the date as seconds
-
Field Details
-
MONTH_NAMES
_more_ -
MILLIS
public static final long MILLISmilliseconds in a millisecond- See Also:
-
MILLIS_SECOND
public static final long MILLIS_SECONDmilliseconds in a second- See Also:
-
MILLIS_MINUTE
public static final long MILLIS_MINUTEmilliseconds in a minute- See Also:
-
MILLIS_HOUR
public static final long MILLIS_HOURmilliseconds in an hour- See Also:
-
MILLIS_DAY
public static final long MILLIS_DAYmilliseconds in a day- See Also:
-
MILLIS_WEEK
public static final long MILLIS_WEEKmilliseconds in a week- See Also:
-
MILLIS_MONTH
public static final long MILLIS_MONTHmilliseconds in a month (approximately)- See Also:
-
MILLIS_YEAR
public static final long MILLIS_YEARmilliseconds in a year (approximately)- See Also:
-
MILLIS_DECADE
public static final long MILLIS_DECADEmilliseconds in a decade (approximately)- See Also:
-
MILLIS_CENTURY
public static final long MILLIS_CENTURYmilliseconds in a century (approximately)- See Also:
-
MILLIS_MILLENIUM
public static final long MILLIS_MILLENIUMmilliseconds in a century (approximately)- See Also:
-
TIMEZONE_GMT
timezone -
TIMEZONE_UTC
_more_ -
DATE_PATTERNS
a set of regular expressions that go along with the below DATE_FORMATS -
DATE_FORMATS
A set of date formats
-
-
Constructor Details
-
DateUtil
public DateUtil()
-
-
Method Details
-
getCurrentSystemTimeAsISO8601
format current time- Returns:
- current time formatted
-
getTimeAsISO8601
format time- Parameters:
date- date- Returns:
- formatted time
-
min
Get the minimum of the 2 dates- Parameters:
date1- date1date2- date2- Returns:
- The minimum of the 2 dates
-
max
Get the maximum of the 2 dates- Parameters:
date1- date1date2- date2- Returns:
- The maximum of the 2 dates
-
getTimeAsISO8601
format time- Parameters:
time- time- Returns:
- formatted time
-
roundByDay
Rounds up or down (if negative) the number of days.- Parameters:
dttm- date to roundday- number of days- Returns:
- rounded date.
-
getFormatters
_more_- Returns:
- _more_
-
findFormatter
This finds the SDF to use for the given date string- Parameters:
dateString- example date- Returns:
- formatter to use
-
getDateRange
This gets a date range based on the text dates. The incoming dates can be of the form:absolute date now (for current time) relative date (e.g., (offset unit), -5 seconds, +2 hours, +5 days, -3 weeks, -1 month This is calculated relative to the other date, e.g: -1 hour, now
- Parameters:
fromDate- from datetoDate- to datedflt- base default date- Returns:
- date range
- Throws:
ParseException- On badness
-
parseRelative
parse the date string (s) (e.g., -1 hour) that is relative to the given baseDate- Parameters:
baseDate- base dates- date stringroundDays- round down or up the given number of days- Returns:
- date
- Throws:
ParseException- on badness
-
parse
Parse the date string- Parameters:
s- date string- Returns:
- date
- Throws:
ParseException- on badness
-
toSeconds
parse the array of date strings and returns the date as seconds- Parameters:
s- array of date strings- Returns:
- array of seconds
- Throws:
ParseException- On badness
-
daysToMillis
public static long daysToMillis(double days) utility to convert a given number of days to milliseconds- Parameters:
days- days- Returns:
- milliseconds
-
hoursToMillis
public static long hoursToMillis(double hour) utility to convert a given number of hours to milliseconds- Parameters:
hour- hours- Returns:
- milliseconds
-
millisToMinutes
public static double millisToMinutes(double millis) utility to convert a given number of milliseconds to minutes- Parameters:
millis- milliseconds- Returns:
- minutes
-
millisToHours
public static double millisToHours(double millis) _more_- Parameters:
millis- _more_- Returns:
- _more_
-
minutesToMillis
public static long minutesToMillis(double minutes) utility to convert a given number of minutes to milliseconds- Parameters:
minutes- minutes- Returns:
- milliseconds
-
getRelativeDate
Get a new date relative to the given date.- Parameters:
from- base daterelativeTimeString- Relative time string, e.g., -1 hour- Returns:
- new date
-
parseRelativeTimeString
Return the delta number of milliseconds specified in the relative time string- Parameters:
relativeTimeString- This is of the form "offset unit", e.g.:-1 hour +2 weeks etc.
- Returns:
- milliseconds
-
decodeWMODate
Decode a date from a WMO header of the form ddHHmm.- Parameters:
wmoDate- WMO header stringbaseDate- base date to get the year and month- Returns:
- the date that is represented by wmoDate
-
main
main- Parameters:
args- args- Throws:
Exception- On badness
-
getDateTimeRangeInHours
public static double getDateTimeRangeInHours(ucar.visad.data.CalendarDateTime fromDate, ucar.visad.data.CalendarDateTime toDate) This is calculated the hour difference between two calendardatetimes- Parameters:
fromDate- from datetoDate- to date- Returns:
- date range
-