org.usergrid.utils
Class DateUtils

java.lang.Object
  extended by org.usergrid.utils.DateUtils

public class DateUtils
extends Object

Utilities for parsing and formatting dates.

Note that this class doesn't use static methods because of the synchronization issues with SimpleDateFormat. This lets synchronization be done on a per-object level, instead of on a per-class level.


Field Summary
protected  SimpleDateFormat alternateIo8601DateParser
          Alternate ISO 8601 parser without fractional seconds
static DateUtils instance
           
protected  SimpleDateFormat iso8601DateParser
          ISO 8601 parser
protected  SimpleDateFormat rfc822DateParser
          RFC 822 parser
 
Constructor Summary
DateUtils()
          Constructs a new DateUtils object, ready to parse/format dates.
 
Method Summary
 String formatIso8601Date(Date date)
          Formats the specified date as an ISO 8601 string.
 String formatRfc822Date(Date date)
          Formats the specified date as an RFC 822 string.
 String iso8601DateNow()
           
 Date parseIso8601Date(String dateString)
          Parses the specified date string as an ISO 8601 date and returns the Date object.
 Date parseRfc822Date(String dateString)
          Parses the specified date string as an RFC 822 date and returns the Date object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

iso8601DateParser

protected final SimpleDateFormat iso8601DateParser
ISO 8601 parser


alternateIo8601DateParser

protected final SimpleDateFormat alternateIo8601DateParser
Alternate ISO 8601 parser without fractional seconds


rfc822DateParser

protected final SimpleDateFormat rfc822DateParser
RFC 822 parser


instance

public static DateUtils instance
Constructor Detail

DateUtils

public DateUtils()
Constructs a new DateUtils object, ready to parse/format dates.

Method Detail

parseIso8601Date

public Date parseIso8601Date(String dateString)
                      throws ParseException
Parses the specified date string as an ISO 8601 date and returns the Date object.

Parameters:
dateString - The date string to parse.
Returns:
The parsed Date object.
Throws:
ParseException - If the date string could not be parsed.

formatIso8601Date

public String formatIso8601Date(Date date)
Formats the specified date as an ISO 8601 string.

Parameters:
date - The date to format.
Returns:
The ISO 8601 string representing the specified date.

iso8601DateNow

public String iso8601DateNow()

formatRfc822Date

public String formatRfc822Date(Date date)
Formats the specified date as an RFC 822 string.

Parameters:
date - The date to format.
Returns:
The RFC 822 string representing the specified date.

parseRfc822Date

public Date parseRfc822Date(String dateString)
                     throws ParseException
Parses the specified date string as an RFC 822 date and returns the Date object.

Parameters:
dateString - The date string to parse.
Returns:
The parsed Date object.
Throws:
ParseException - If the date string could not be parsed.


Copyright © 2013. All Rights Reserved.