Package ucar.nc2.units
Class DateFromString
java.lang.Object
ucar.nc2.units.DateFromString
Convenience routines for parsing a String to produce a Date.
- Since:
- Nov 29, 2005 4:53:46 PM
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic DategetDateUsingCompleteDateFormat(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.static DategetDateUsingCompleteDateFormatWithOffset(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.static DategetDateUsingDemarkatedCount(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.static DategetDateUsingDemarkatedMatch(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.static DategetDateUsingDemarkatedMatchOld(String dateString, String dateFormatString, char demark) Deprecated.do not usestatic DategetDateUsingRegExp(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".static DategetDateUsingRegExpAndDateFormat(String dateString, String matchPattern, String substitutionPattern, String dateFormatString) The same as getDateUsingRegExp() except the date format string to be used must be specified.static DategetDateUsingSimpleDateFormat(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.static DoublegetHourUsingDemarkatedMatch(String hourString, String formatString, char demark) Deprecated.do not use
-
Constructor Details
-
DateFromString
public DateFromString()
-
-
Method Details
-
getDateUsingSimpleDateFormat
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 parseddateFormatString- 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 parseddateFormatString- the date format Stringdemark- 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 parseddateFormatString- the date format Stringdemark- 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
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 parseddateFormatString- 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 parseddateFormatString- the date format StringstartIndex- 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 parsedmatchPattern- 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 parsedmatchPattern- 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
-