Class DateFromString

java.lang.Object
ucar.nc2.units.DateFromString

public class DateFromString extends Object
Convenience routines for parsing a String to produce a Date.
Since:
Nov 29, 2005 4:53:46 PM
  • Constructor Details

    • DateFromString

      public DateFromString()
  • Method Details

    • getDateUsingSimpleDateFormat

      public static Date getDateUsingSimpleDateFormat(String dateString, String dateFormatString)
      Parse the given date string (starting at the first numeric character) using the given date format string (as described in java.text.SimpleDateFormat) and return a Date.
      Parameters:
      dateString - the String to be parsed
      dateFormatString - the date format String
      Returns:
      the Date that was parsed.
    • getDateUsingDemarkatedCount

      public static Date getDateUsingDemarkatedCount(String dateString, String dateFormatString, char demark)
      Parse the given date string, starting at a position given by the offset of the demark character in the dateFormatString. The rest of the dateFormatString is the date format string (as described in java.text.SimpleDateFormat).
        Example:
         dateString =        wrfout_d01_2006-07-06_080000.nc
         dateFormatString = wrfout_d01_#yyyy-MM-dd_HHmm
       
      This simply counts over "wrfout_d01_" number of chars in dateString, then applies the remaining dateFormatString.
      Parameters:
      dateString - the String to be parsed
      dateFormatString - the date format String
      demark - the demarkation character
      Returns:
      the Date that was parsed.
    • getDateUsingDemarkatedMatch

      public static Date getDateUsingDemarkatedMatch(String dateString, String dateFormatString, char demark)
      Parse the given date string (between the demarcation characters) using the given date format string (as described in java.text.SimpleDateFormat) and return a Date.
       Example:
        dateString =  /data/anything/2006070611/wrfout_d01_2006-07-06_080000.nc
        dateFormatString =                    #wrfout_d01_#yyyy-MM-dd_HHmm
        would extract the date 2006-07-06T08:00
      
        dateString =  /data/anything/2006070611/wrfout_d01_2006-07-06_080000.nc
        dateFormatString =          yyyyMMddHH#/wrfout_d01_#
        would extract the date 2006-07-06T11:00
       
      Parameters:
      dateString - the String to be parsed
      dateFormatString - the date format String
      demark - the demarkation character
      Returns:
      the Date that was parsed.
    • getDateUsingDemarkatedMatchOld

      @Deprecated public static Date getDateUsingDemarkatedMatchOld(String dateString, String dateFormatString, char demark)
      Deprecated.
      do not use
    • getHourUsingDemarkatedMatch

      @Deprecated public static Double getHourUsingDemarkatedMatch(String hourString, String formatString, char demark)
      Deprecated.
      do not use
    • getDateUsingCompleteDateFormat

      public static Date getDateUsingCompleteDateFormat(String dateString, String dateFormatString)
      Parse the given date string using the given date format string (as described in java.text.SimpleDateFormat) and return a Date.
      Parameters:
      dateString - the String to be parsed
      dateFormatString - the date format String
      Returns:
      the Date that was parsed.
    • getDateUsingCompleteDateFormatWithOffset

      public static Date getDateUsingCompleteDateFormatWithOffset(String dateString, String dateFormatString, int startIndex)
      Parse the given date string (starting at the given startIndex) using the given date format string (as described in java.text.SimpleDateFormat) and return a Date. Assumes TimeZone is GMT.
      Parameters:
      dateString - the String to be parsed
      dateFormatString - the date format String
      startIndex - the index at which to start parsing the date string
      Returns:
      the Date that was parsed.
    • getDateUsingRegExp

      public static Date getDateUsingRegExp(String dateString, String matchPattern, String substitutionPattern)
      Use regular expression capture group replacement to construct a date string and return the Date that is obtained by parseing the constructed date string using the date format string "yyyy-MM-dd'T'HH:mm". The date string is constructed by matching the given dateString against the given regular expression matchPattern and then using the capture groups from the match to replace the capture group references, i.e., "$n", where n is an integer.
      Parameters:
      dateString - the String to be parsed
      matchPattern - the regular expression String on which to match.
      substitutionPattern - the String to use in the capture group replacement.
      Returns:
      the calculated Date
    • getDateUsingRegExpAndDateFormat

      public static Date getDateUsingRegExpAndDateFormat(String dateString, String matchPattern, String substitutionPattern, String dateFormatString)
      The same as getDateUsingRegExp() except the date format string to be used must be specified.
      Parameters:
      dateString - the String to be parsed
      matchPattern - the regular expression String on which to match.
      substitutionPattern - the String to use in the capture group replacement.
      dateFormatString - the date format string to use in the parsing of the date string.
      Returns:
      the calculated Date