org.dellroad.stuff.string
Class DateEncoder

java.lang.Object
  extended by org.dellroad.stuff.string.DateEncoder

public final class DateEncoder
extends Object

Encodes Date objects to and from strings.


Field Summary
static String PATTERN
          Regular expression matching properly encoded strings.
 
Method Summary
static Date decode(String string)
          Decode the given date.
static String encode(Date date)
          Encode the given date as a string of the form 2009-12-01T15:33:07.763Z.
static SimpleDateFormat getDateFormat(String format)
          Get a SimpleDateFormat configured with the given format and for the UTC time zone and strict parsing.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PATTERN

public static final String PATTERN
Regular expression matching properly encoded strings.

See Also:
Constant Field Values
Method Detail

encode

public static String encode(Date date)
Encode the given date as a string of the form 2009-12-01T15:33:07.763Z. If the fractional seconds portion is zero, it will be omitted.

Parameters:
date - date to encode
Throws:
NullPointerException - if date is null

decode

public static Date decode(String string)
Decode the given date.

Parameters:
string - encoded date
Throws:
IllegalArgumentException - if string is malformed
NullPointerException - if string is null

getDateFormat

public static SimpleDateFormat getDateFormat(String format)
Get a SimpleDateFormat configured with the given format and for the UTC time zone and strict parsing.

Parameters:
format - date format string