com.devexperts.qd.util
Class TimeFormat

java.lang.Object
  extended by com.devexperts.qd.util.TimeFormat

public class TimeFormat
extends java.lang.Object

Utility class for parsing and formatting dates and times.


Field Summary
static TimeFormat DEFAULT
           
static TimeFormat GMT
           
 
Constructor Summary
TimeFormat(java.util.TimeZone timezone)
          Creates new TimeFormat with specified timezone.
 
Method Summary
 java.lang.String formatDateTime(java.util.Date time)
          Converts Date into String, formatted like yyyyMMdd-HHmmssZ.
 java.lang.String formatDateTimeWithMillis(java.util.Date time)
          Converts Date into String, formatted like yyyyMMdd-HHmmss.SSSZ.
 java.lang.String formatDateTimeWithMillisWithoutTimeZone(java.util.Date time)
          Converts Date into String, formatted like yyyyMMdd-HHmmss.SSS.
 java.lang.String formatDateTimeWithoutTimeZone(java.util.Date time)
          Converts Date into String, formatted like yyyyMMdd-HHmmss.
 java.util.TimeZone getTimeZone()
          Returns default timezone of current TimeFormat.
 java.util.Date parseDateTime(java.lang.String value)
          Reads Date from String.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT

public static final TimeFormat DEFAULT

GMT

public static final TimeFormat GMT
Constructor Detail

TimeFormat

public TimeFormat(java.util.TimeZone timezone)
Creates new TimeFormat with specified timezone.

Parameters:
timezone - default timezone for this TimeFormat.
Throws:
java.lang.NullPointerException - if timezone is null.
Method Detail

parseDateTime

public java.util.Date parseDateTime(java.lang.String value)
                             throws InvalidFormatException,
                                    java.lang.NullPointerException
Reads Date from String.

It accepts the following formats of date:

Here

Parameters:
value - String value to parse.
Returns:
Date parsed from value.
Throws:
InvalidFormatException - if value has wrong format.
java.lang.NullPointerException - if value == null.
See Also:
SimpleDateFormat

formatDateTime

public java.lang.String formatDateTime(java.util.Date time)
                                throws java.lang.NullPointerException
Converts Date into String, formatted like yyyyMMdd-HHmmssZ. Time zone is formatted according to RFC 822 format (for example "+0300").

Parameters:
time - Date to format.
Returns:
String representation of time.
Throws:
java.lang.NullPointerException - if time is null.

formatDateTimeWithoutTimeZone

public java.lang.String formatDateTimeWithoutTimeZone(java.util.Date time)
                                               throws java.lang.NullPointerException
Converts Date into String, formatted like yyyyMMdd-HHmmss. Unlike formatDateTime(java.util.Date), it doesn't declare time zone and formats time in current time zone.

Parameters:
time - Date to format.
Returns:
String representation of time.
Throws:
java.lang.NullPointerException - if time is null.

formatDateTimeWithMillis

public java.lang.String formatDateTimeWithMillis(java.util.Date time)
                                          throws java.lang.NullPointerException
Converts Date into String, formatted like yyyyMMdd-HHmmss.SSSZ. Time zone is formatted according to RFC 822 format (for example "+0300").

Parameters:
time - Date to format.
Returns:
String representation of time.
Throws:
java.lang.NullPointerException - if time is null.

formatDateTimeWithMillisWithoutTimeZone

public java.lang.String formatDateTimeWithMillisWithoutTimeZone(java.util.Date time)
                                                         throws java.lang.NullPointerException
Converts Date into String, formatted like yyyyMMdd-HHmmss.SSS. Unlike formatDateTime(java.util.Date), it doesn't declare time zone and formats time in current time zone.

Parameters:
time - Date to format.
Returns:
String representation of time.
Throws:
java.lang.NullPointerException - if time is null.

getTimeZone

public java.util.TimeZone getTimeZone()
Returns default timezone of current TimeFormat.

Returns:
default timezone of current TimeFormat.