Package edu.uiuc.ncsa.security.core.util
Class Iso8601
- java.lang.Object
- 
- edu.uiuc.ncsa.security.core.util.Iso8601
 
- 
 public class Iso8601 extends Object This class provides some utilities for creating and parsing ISO 8601 dates. It dates way back to Java 2 or so and should probably be replaced by java.time classes in introduced in Java 8. It is very widely used in Sec-Lib and other projects.CommentaryThis has a few things that need to be mentioned. As per contract
 date to string conversions always only return a date in UTC, i.e., ending with a "Z"
 string to date allows 0 - 3 digits accuracy and various (incl. fractional) time zones which can be notated as +-xxxx or +-xx:xx.
 therefore round-tripping of dates is consistent but not quite straightforward. The actual values of the dates never change but string comparisons might fail. For instance, a date in one timezone will in general not be equal as a formatted string to another in a different timezone, but might be completely identical as date objects.
 Important technical note: There is a "feature" in java'sSimpleDateFormatclass. In particular, fractions of seconds are handled in an unintiutive way so that errors were being consistently introduced. The methodfixSecondsfixes this and there are regression tests to catch this now as well.
- 
- 
Constructor SummaryConstructors Constructor Description Iso8601()
 - 
Method SummaryAll Methods Static Methods Concrete Methods Modifier and Type Method Description static Stringdate2String(long d)Convert a date to a string in the formatstatic Stringdate2String(Calendar c)Convert a date to a string in the formatstatic Stringdate2String(Date d)Convert a date to a string in the formatprotected static StringfixSeconds(String rawDate)This normalizes the date so that it always has 3 places for the number of milliseconds.static DateFormatgetDateFormat()Provides the DateFormat used by this utility.static DateFormatgetUTCDateFormat()Provides the date format for UTC used by this utility.static voidmain(String[] args)demo of this classprotected static CalendarmintCalendar()Create a new Calendarstatic String[]splitDate(String rawDate)static Calendarstring2Date(String s)Convert a string in the format
 
- 
- 
- 
Field Detail- 
zerosprotected static String zeros 
 
- 
 - 
Method Detail- 
date2Stringpublic static String date2String(long d) Convert a date to a string in the format
 where "Z" represents UTC.yyyy-MM-dd'T'HH:mm:ss.SSS'Z' - Parameters:
- d- the date in milliseconds
- Returns:
- the string representation of the date
 
 - 
date2Stringpublic static String date2String(Date d) Convert a date to a string in the format
 where "Z" represents UTC.yyyy-MM-dd'T'HH:mm:ss.SSS'Z' - Parameters:
- d- the date
- Returns:
- the string representation of the date
 
 - 
date2Stringpublic static String date2String(Calendar c) Convert a date to a string in the format
 where "Z" represents UTC.yyyy-MM-dd'T'HH:mm:ss.SSS'Z' - Parameters:
- c- the date
- Returns:
- the string representation of the date
 
 - 
getUTCDateFormatpublic static DateFormat getUTCDateFormat() Provides the date format for UTC used by this utility. Normally it is a good idea to use the built in methods of this class and this is provided for backwards compatibility with earlier releases.- Returns:
 
 - 
getDateFormatpublic static DateFormat getDateFormat() Provides the DateFormat used by this utility.- Returns:
 
 - 
fixSecondsprotected static String fixSeconds(String rawDate) throws ParseException This normalizes the date so that it always has 3 places for the number of milliseconds. This is unavoidable since there is a serious feature in java's simple date format that will introduce errors.- Parameters:
- rawDate-
- Returns:
- Throws:
- ParseException
 
 - 
splitDatepublic static String[] splitDate(String rawDate) throws ParseException - Throws:
- ParseException
 
 - 
string2Datepublic static Calendar string2Date(String s) throws ParseException Convert a string in the format
 where tzd is either "Z" for UTC or an offset in the format [+-]hh:mm to a date.yyyy-MM-dd'T'HH:mm:ss.S[tzd] - Parameters:
- s-
- Returns:
- Throws:
- ParseException
 
 - 
mintCalendarprotected static Calendar mintCalendar() Create a new Calendar- Returns:
 
 - 
mainpublic static void main(String[] args) demo of this class- Parameters:
- args-
 
 
- 
 
-