public class DateUtil
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static java.lang.String[] |
DATE_FORMATS
A set of date formats
|
static java.lang.String[] |
DATE_PATTERNS
a set of regular expressions that go along with the below DATE_FORMATS
|
static long |
MILLIS
milliseconds in a millisecond
|
static long |
MILLIS_CENTURY
milliseconds in a century (approximately)
|
static long |
MILLIS_DAY
milliseconds in a day
|
static long |
MILLIS_DECADE
milliseconds in a decade (approximately)
|
static long |
MILLIS_HOUR
milliseconds in an hour
|
static long |
MILLIS_MILLENIUM
milliseconds in a century (approximately)
|
static long |
MILLIS_MINUTE
milliseconds in a minute
|
static long |
MILLIS_MONTH
milliseconds in a month (approximately)
|
static long |
MILLIS_SECOND
milliseconds in a second
|
static long |
MILLIS_WEEK
milliseconds in a week
|
static long |
MILLIS_YEAR
milliseconds in a year (approximately)
|
static java.lang.String[] |
MONTH_NAMES
_more_
|
static java.util.TimeZone |
TIMEZONE_GMT
timezone
|
static java.util.TimeZone |
TIMEZONE_UTC
_more_
|
Constructor and Description |
---|
DateUtil() |
Modifier and Type | Method and Description |
---|---|
static long |
daysToMillis(double days)
utility to convert a given number of days to milliseconds
|
static java.util.Date |
decodeWMODate(java.lang.String wmoDate,
java.util.Date baseDate)
Decode a date from a WMO header of the form ddHHmm.
|
static java.text.SimpleDateFormat |
findFormatter(java.lang.String dateString)
This finds the SDF to use for the given date string
|
static java.lang.String |
getCurrentSystemTimeAsISO8601()
format current time
|
static java.util.Date[] |
getDateRange(java.lang.String fromDate,
java.lang.String toDate,
java.util.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 calendardatetimes
|
static java.text.SimpleDateFormat[] |
getFormatters()
_more_
|
static java.util.Date |
getRelativeDate(java.util.Date from,
java.lang.String relativeTimeString)
Get a new date relative to the given date.
|
static java.lang.String |
getTimeAsISO8601(java.util.Date date)
format time
|
static java.lang.String |
getTimeAsISO8601(long time)
format time
|
static long |
hoursToMillis(double hour)
utility to convert a given number of hours to milliseconds
|
static void |
main(java.lang.String[] args)
main
|
static java.util.Date |
max(java.util.Date date1,
java.util.Date date2)
Get the maximum of the 2 dates
|
static double |
millisToHours(double millis)
_more_
|
static double |
millisToMinutes(double millis)
utility to convert a given number of milliseconds to minutes
|
static java.util.Date |
min(java.util.Date date1,
java.util.Date date2)
Get the minimum of the 2 dates
|
static long |
minutesToMillis(double minutes)
utility to convert a given number of minutes to milliseconds
|
static java.util.Date |
parse(java.lang.String s)
Parse the date string
|
static java.util.Date |
parseRelative(java.util.Date baseDate,
java.lang.String s,
int roundDays)
parse the date string (s) (e.g., -1 hour) that is relative to the given baseDate
|
static long |
parseRelativeTimeString(java.lang.String relativeTimeString)
Return the delta number of milliseconds specified in the relative time string
|
static java.util.Date |
roundByDay(java.util.Date dttm,
int day)
Rounds up or down (if negative) the number of days.
|
static double[] |
toSeconds(java.lang.String[] s)
parse the array of date strings and returns the date as seconds
|
public static final java.lang.String[] MONTH_NAMES
public static final long MILLIS
public static final long MILLIS_SECOND
public static final long MILLIS_MINUTE
public static final long MILLIS_HOUR
public static final long MILLIS_DAY
public static final long MILLIS_WEEK
public static final long MILLIS_MONTH
public static final long MILLIS_YEAR
public static final long MILLIS_DECADE
public static final long MILLIS_CENTURY
public static final long MILLIS_MILLENIUM
public static final java.util.TimeZone TIMEZONE_GMT
public static final java.util.TimeZone TIMEZONE_UTC
public static final java.lang.String[] DATE_PATTERNS
public static final java.lang.String[] DATE_FORMATS
public static java.lang.String getCurrentSystemTimeAsISO8601()
public static java.lang.String getTimeAsISO8601(java.util.Date date)
date
- datepublic static java.util.Date min(java.util.Date date1, java.util.Date date2)
date1
- date1date2
- date2public static java.util.Date max(java.util.Date date1, java.util.Date date2)
date1
- date1date2
- date2public static java.lang.String getTimeAsISO8601(long time)
time
- timepublic static java.util.Date roundByDay(java.util.Date dttm, int day)
dttm
- date to roundday
- number of dayspublic static java.text.SimpleDateFormat[] getFormatters()
public static java.text.SimpleDateFormat findFormatter(java.lang.String dateString)
dateString
- example datepublic static java.util.Date[] getDateRange(java.lang.String fromDate, java.lang.String toDate, java.util.Date dflt) throws java.text.ParseException
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
fromDate
- from datetoDate
- to datedflt
- base default datejava.text.ParseException
- On badnesspublic static java.util.Date parseRelative(java.util.Date baseDate, java.lang.String s, int roundDays) throws java.text.ParseException
baseDate
- base dates
- date stringroundDays
- round down or up the given number of daysjava.text.ParseException
- on badnesspublic static java.util.Date parse(java.lang.String s) throws java.text.ParseException
s
- date stringjava.text.ParseException
- on badnesspublic static double[] toSeconds(java.lang.String[] s) throws java.text.ParseException
s
- array of date stringsjava.text.ParseException
- On badnesspublic static long daysToMillis(double days)
days
- dayspublic static long hoursToMillis(double hour)
hour
- hourspublic static double millisToMinutes(double millis)
millis
- millisecondspublic static double millisToHours(double millis)
millis
- _more_public static long minutesToMillis(double minutes)
minutes
- minutespublic static java.util.Date getRelativeDate(java.util.Date from, java.lang.String relativeTimeString)
from
- base daterelativeTimeString
- Relative time string, e.g., -1 hourpublic static long parseRelativeTimeString(java.lang.String relativeTimeString)
relativeTimeString
- This is of the form "offset unit", e.g.:-1 hour +2 weeks etc.
public static java.util.Date decodeWMODate(java.lang.String wmoDate, java.util.Date baseDate)
wmoDate
- WMO header stringbaseDate
- base date to get the year and monthpublic static void main(java.lang.String[] args) throws java.lang.Exception
args
- argsjava.lang.Exception
- On badnesspublic static double getDateTimeRangeInHours(ucar.visad.data.CalendarDateTime fromDate, ucar.visad.data.CalendarDateTime toDate)
fromDate
- from datetoDate
- to date