Class DateUtil

java.lang.Object
ucar.unidata.util.DateUtil

public class DateUtil extends Object
A set of date oriented utilities
Since:
May 4, 2007 1:01:53 PM
Author:
edavis and the IDV development team
  • Field Details

    • MONTH_NAMES

      public static final String[] MONTH_NAMES
      _more_
    • MILLIS

      public static final long MILLIS
      milliseconds in a millisecond
      See Also:
    • MILLIS_SECOND

      public static final long MILLIS_SECOND
      milliseconds in a second
      See Also:
    • MILLIS_MINUTE

      public static final long MILLIS_MINUTE
      milliseconds in a minute
      See Also:
    • MILLIS_HOUR

      public static final long MILLIS_HOUR
      milliseconds in an hour
      See Also:
    • MILLIS_DAY

      public static final long MILLIS_DAY
      milliseconds in a day
      See Also:
    • MILLIS_WEEK

      public static final long MILLIS_WEEK
      milliseconds in a week
      See Also:
    • MILLIS_MONTH

      public static final long MILLIS_MONTH
      milliseconds in a month (approximately)
      See Also:
    • MILLIS_YEAR

      public static final long MILLIS_YEAR
      milliseconds in a year (approximately)
      See Also:
    • MILLIS_DECADE

      public static final long MILLIS_DECADE
      milliseconds in a decade (approximately)
      See Also:
    • MILLIS_CENTURY

      public static final long MILLIS_CENTURY
      milliseconds in a century (approximately)
      See Also:
    • MILLIS_MILLENIUM

      public static final long MILLIS_MILLENIUM
      milliseconds in a century (approximately)
      See Also:
    • TIMEZONE_GMT

      public static final TimeZone TIMEZONE_GMT
      timezone
    • TIMEZONE_UTC

      public static final TimeZone TIMEZONE_UTC
      _more_
    • DATE_PATTERNS

      public static final String[] DATE_PATTERNS
      a set of regular expressions that go along with the below DATE_FORMATS
    • DATE_FORMATS

      public static final String[] DATE_FORMATS
      A set of date formats
  • Constructor Details

    • DateUtil

      public DateUtil()
  • Method Details

    • getCurrentSystemTimeAsISO8601

      public static String getCurrentSystemTimeAsISO8601()
      format current time
      Returns:
      current time formatted
    • getTimeAsISO8601

      public static String getTimeAsISO8601(Date date)
      format time
      Parameters:
      date - date
      Returns:
      formatted time
    • min

      public static Date min(Date date1, Date date2)
      Get the minimum of the 2 dates
      Parameters:
      date1 - date1
      date2 - date2
      Returns:
      The minimum of the 2 dates
    • max

      public static Date max(Date date1, Date date2)
      Get the maximum of the 2 dates
      Parameters:
      date1 - date1
      date2 - date2
      Returns:
      The maximum of the 2 dates
    • getTimeAsISO8601

      public static String getTimeAsISO8601(long time)
      format time
      Parameters:
      time - time
      Returns:
      formatted time
    • roundByDay

      public static Date roundByDay(Date dttm, int day)
      Rounds up or down (if negative) the number of days.
      Parameters:
      dttm - date to round
      day - number of days
      Returns:
      rounded date.
    • getFormatters

      public static SimpleDateFormat[] getFormatters()
      _more_
      Returns:
      _more_
    • findFormatter

      public static SimpleDateFormat findFormatter(String dateString)
      This finds the SDF to use for the given date string
      Parameters:
      dateString - example date
      Returns:
      formatter to use
    • getDateRange

      public static Date[] getDateRange(String fromDate, String toDate, Date dflt) throws ParseException
      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 date
      toDate - to date
      dflt - base default date
      Returns:
      date range
      Throws:
      ParseException - On badness
    • parseRelative

      public static Date parseRelative(Date baseDate, String s, int roundDays) throws ParseException
      parse the date string (s) (e.g., -1 hour) that is relative to the given baseDate
      Parameters:
      baseDate - base date
      s - date string
      roundDays - round down or up the given number of days
      Returns:
      date
      Throws:
      ParseException - on badness
    • parse

      public static Date parse(String s) throws ParseException
      Parse the date string
      Parameters:
      s - date string
      Returns:
      date
      Throws:
      ParseException - on badness
    • toSeconds

      public static double[] toSeconds(String[] s) throws ParseException
      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

      public static Date getRelativeDate(Date from, String relativeTimeString)
      Get a new date relative to the given date.
      Parameters:
      from - base date
      relativeTimeString - Relative time string, e.g., -1 hour
      Returns:
      new date
    • parseRelativeTimeString

      public static long parseRelativeTimeString(String relativeTimeString)
      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

      public static Date decodeWMODate(String wmoDate, Date baseDate)
      Decode a date from a WMO header of the form ddHHmm.
      Parameters:
      wmoDate - WMO header string
      baseDate - base date to get the year and month
      Returns:
      the date that is represented by wmoDate
    • main

      public static void main(String[] args) throws Exception
      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 date
      toDate - to date
      Returns:
      date range