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 long
milliseconds in a millisecondstatic final long
milliseconds in a century (approximately)static final long
milliseconds in a daystatic final long
milliseconds in a decade (approximately)static final long
milliseconds in an hourstatic final long
milliseconds in a century (approximately)static final long
milliseconds in a minutestatic final long
milliseconds in a month (approximately)static final long
milliseconds in a secondstatic final long
milliseconds in a weekstatic final long
milliseconds in a year (approximately)static final String[]
_more_static final TimeZone
timezonestatic final TimeZone
_more_ -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic long
daysToMillis
(double days) utility to convert a given number of days to millisecondsstatic Date
decodeWMODate
(String wmoDate, Date baseDate) Decode a date from a WMO header of the form ddHHmm.static SimpleDateFormat
findFormatter
(String dateString) This finds the SDF to use for the given date stringstatic String
format current timestatic Date[]
getDateRange
(String fromDate, String toDate, Date dflt) This gets a date range based on the text dates.static double
getDateTimeRangeInHours
(ucar.visad.data.CalendarDateTime fromDate, ucar.visad.data.CalendarDateTime toDate) This is calculated the hour difference between two calendardatetimesstatic SimpleDateFormat[]
_more_static Date
getRelativeDate
(Date from, String relativeTimeString) Get a new date relative to the given date.static String
getTimeAsISO8601
(long time) format timestatic String
getTimeAsISO8601
(Date date) format timestatic long
hoursToMillis
(double hour) utility to convert a given number of hours to millisecondsstatic void
mainstatic Date
Get the maximum of the 2 datesstatic double
millisToHours
(double millis) _more_static double
millisToMinutes
(double millis) utility to convert a given number of milliseconds to minutesstatic Date
Get the minimum of the 2 datesstatic long
minutesToMillis
(double minutes) utility to convert a given number of minutes to millisecondsstatic Date
Parse the date stringstatic Date
parseRelative
(Date baseDate, String s, int roundDays) parse the date string (s) (e.g., -1 hour) that is relative to the given baseDatestatic long
parseRelativeTimeString
(String relativeTimeString) Return the delta number of milliseconds specified in the relative time stringstatic Date
roundByDay
(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
-