ProgramixGenericLib v5.0.1

com.programix.time
Class DateTimeFormat

java.lang.Object
  extended by com.programix.time.DateTimeFormat
All Implemented Interfaces:
Serializable, Comparable<DateTimeFormat>

public final class DateTimeFormat
extends Object
implements Serializable, Comparable<DateTimeFormat>

Used to specify the format for a date/time for the Gregorian calendar. Year is formatted using four digits, month as 01 to 12, day as 01 to 28, , 30, or 31 (depending on the month and year). Hour uses the 24-hour style as 00 to 23. Minute as 00 to 59. Second as 00 to 59. Millisecond as 000 to 999. Colons are used between the hour, minute, and second fields. A period is used between the second and millisecond fields. A space is used between the date and time sections.

Author:
Paul Hyde
See Also:
DateTools, DateTime, DateTimeField, Serialized Form

Field Summary
static DateTimeFormat MDY_DASH
          Format: mm-dd-yyyy.
static DateTimeFormat MDY_DOT
          Format: mm.dd.yyyy.
static DateTimeFormat MDY_HM_DASH
          Format: mm-dd-yyyy hh:mm.
static DateTimeFormat MDY_HM_DOT
          Format: mm.dd.yyyy hh:mm.
static DateTimeFormat MDY_HM_SLASH
          Format: mm/dd/yyyy hh:mm.
static DateTimeFormat MDY_HMS_DASH
          Format: mm-dd-yyyy hh:mm:ss.
static DateTimeFormat MDY_HMS_DOT
          Format: mm.dd.yyyy hh:mm:ss.
static DateTimeFormat MDY_HMS_SLASH
          Format: mm/dd/yyyy hh:mm:ss.
static DateTimeFormat MDY_HMSF_DASH
          Format: mm-dd-yyyy hh:mm:ss.fff.
static DateTimeFormat MDY_HMSF_DOT
          Format: mm.dd.yyyy hh:mm:ss.fff.
static DateTimeFormat MDY_HMSF_SLASH
          Format: mm/dd/yyyy hh:mm:ss.fff.
static DateTimeFormat MDY_NONE
          Format: mmddyyyy.
static DateTimeFormat MDY_SLASH
          Format: mm/dd/yyyy.
static List<DateTimeFormat> VALUE_LIST
          An unmodifiable List of all the instances of DateTimeFormat.
static DateTimeFormat YMD_DASH
          Format: yyyy-mm-dd.
static DateTimeFormat YMD_DOT
          Format: yyyy.mm.dd.
static DateTimeFormat YMD_HM_DASH
          Format: yyyy-mm-dd hh:mm.
static DateTimeFormat YMD_HM_DOT
          Format: yyyy.mm.dd hh:mm.
static DateTimeFormat YMD_HM_NONE
          Format: yyyymmddhhmm.
static DateTimeFormat YMD_HM_SLASH
          Format: yyyy/mm/dd hh:mm.
static DateTimeFormat YMD_HMS_DASH
          Format: yyyy-mm-dd hh:mm:ss.
static DateTimeFormat YMD_HMS_DOT
          Format: yyyy.mm.dd hh:mm:ss.
static DateTimeFormat YMD_HMS_NONE
          Format: yyyymmddhhmmss.
static DateTimeFormat YMD_HMS_SLASH
          Format: yyyy/mm/dd hh:mm:ss.
static DateTimeFormat YMD_HMSF_DASH
          Format: yyyy-mm-dd hh:mm:ss.fff.
static DateTimeFormat YMD_HMSF_DOT
          Format: yyyy.mm.dd hh:mm:ss.fff.
static DateTimeFormat YMD_HMSF_SLASH
          Format: yyyy/mm/dd hh:mm:ss.fff.
static DateTimeFormat YMD_NONE
          Format: yyyymmdd.
static DateTimeFormat YMD_SLASH
          Format: yyyy/mm/dd.
 
Method Summary
 int compareTo(DateTimeFormat other)
           
 boolean equals(Object obj)
           
 String format(Calendar cal)
          Formats the date/time stored in the specified Calendar returning the text in a String.
 StringBuffer format(Calendar cal, StringBuffer appendTo)
          Formats the date/time stored in the specified Calendar appending the text to the specified StringBuffer.
 String getName()
          Returns the name of this format.
static DateTimeFormat[] getValues()
          Returns an array of all the instances of DateTimeFormat.
 int hashCode()
           
 String toString()
           
static DateTimeFormat valueOf(String name)
          Returns the instance whose getName() method returns a String that matches the name passed in.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

YMD_HMSF_DASH

public static final DateTimeFormat YMD_HMSF_DASH
Format: yyyy-mm-dd hh:mm:ss.fff. Formats the date as year, month, day, hour, minute, second, millisecond with dashes delimiting the date portion. Example: 2004-12-19 15:45:52.809.


YMD_HMSF_SLASH

public static final DateTimeFormat YMD_HMSF_SLASH
Format: yyyy/mm/dd hh:mm:ss.fff. Formats the date as year, month, day, hour, minute, second, millisecond with slashes delimiting the date portion. Example: 2004/12/19 15:45:52.809.


YMD_HMSF_DOT

public static final DateTimeFormat YMD_HMSF_DOT
Format: yyyy.mm.dd hh:mm:ss.fff. Formats the date as year, month, day, hour, minute, second, millisecond with dots delimiting the date portion. Example: 2004.12.19 15:45:52.809.


MDY_HMSF_DASH

public static final DateTimeFormat MDY_HMSF_DASH
Format: mm-dd-yyyy hh:mm:ss.fff. Formats the date as month, day, year, hour, minute, second, millisecond with dashes delimiting the date portion. Example: 12-19-2004 15:45:52.809.


MDY_HMSF_SLASH

public static final DateTimeFormat MDY_HMSF_SLASH
Format: mm/dd/yyyy hh:mm:ss.fff. Formats the date as month, day, year, hour, minute, second, millisecond with slashes delimiting the date portion. Example: 12/19/2004 15:45:52.809.


MDY_HMSF_DOT

public static final DateTimeFormat MDY_HMSF_DOT
Format: mm.dd.yyyy hh:mm:ss.fff. Formats the date as month, day, year, hour, minute, second, millisecond with dots delimiting the date portion. Example: 12.19.2004 15:45:52.809.


YMD_HMS_DASH

public static final DateTimeFormat YMD_HMS_DASH
Format: yyyy-mm-dd hh:mm:ss. Formats the date as year, month, day, hour, minute, second with dashes delimiting the date portion. Example: 2004-12-19 15:45:52.


YMD_HMS_SLASH

public static final DateTimeFormat YMD_HMS_SLASH
Format: yyyy/mm/dd hh:mm:ss. Formats the date as year, month, day, hour, minute, second with slashes delimiting the date portion. Example: 2004/12/19 15:45:52.


YMD_HMS_DOT

public static final DateTimeFormat YMD_HMS_DOT
Format: yyyy.mm.dd hh:mm:ss. Formats the date as year, month, day, hour, minute, second with dots delimiting the date portion. Example: 2004.12.19 15:45:52.


YMD_HMS_NONE

public static final DateTimeFormat YMD_HMS_NONE
Format: yyyymmddhhmmss. Formats the date as year, month, day, hour, minute, second with nothing delimiting the date or time portion. Example: 20041219154552.


MDY_HMS_DASH

public static final DateTimeFormat MDY_HMS_DASH
Format: mm-dd-yyyy hh:mm:ss. Formats the date as month, day, year, hour, minute, second with dashes delimiting the date portion. Example: 12-19-2004 15:45:52.


MDY_HMS_SLASH

public static final DateTimeFormat MDY_HMS_SLASH
Format: mm/dd/yyyy hh:mm:ss. Formats the date as month, day, year, hour, minute, second with slashes delimiting the date portion. Example: 12/19/2004 15:45:52.


MDY_HMS_DOT

public static final DateTimeFormat MDY_HMS_DOT
Format: mm.dd.yyyy hh:mm:ss. Formats the date as month, day, year, hour, minute, second with dots delimiting the date portion. Example: 12.19.2004 15:45:52.


YMD_HM_DASH

public static final DateTimeFormat YMD_HM_DASH
Format: yyyy-mm-dd hh:mm. Formats the date as year, month, day, hour, minute with dashes delimiting the date portion. Example: 2004-12-19 15:45.


YMD_HM_SLASH

public static final DateTimeFormat YMD_HM_SLASH
Format: yyyy/mm/dd hh:mm. Formats the date as year, month, day, hour, minute with slashes delimiting the date portion. Example: 2004/12/19 15:45.


YMD_HM_DOT

public static final DateTimeFormat YMD_HM_DOT
Format: yyyy.mm.dd hh:mm. Formats the date as year, month, day, hour, minute with dots delimiting the date portion. Example: 2004.12.19 15:45.


YMD_HM_NONE

public static final DateTimeFormat YMD_HM_NONE
Format: yyyymmddhhmm. Formats the date as year, month, day, hour, minute with nothing delimiting the date or time portion. Example: 200412191545.


MDY_HM_DASH

public static final DateTimeFormat MDY_HM_DASH
Format: mm-dd-yyyy hh:mm. Formats the date as month, day, year, hour, minute with dashes delimiting the date portion. Example: 12-19-2004 15:45.


MDY_HM_SLASH

public static final DateTimeFormat MDY_HM_SLASH
Format: mm/dd/yyyy hh:mm. Formats the date as month, day, year, hour, minute with slashes delimiting the date portion. Example: 12/19/2004 15:45.


MDY_HM_DOT

public static final DateTimeFormat MDY_HM_DOT
Format: mm.dd.yyyy hh:mm. Formats the date as month, day, year, hour, minute with dots delimiting the date portion. Example: 12.19.2004 15:45.


YMD_DASH

public static final DateTimeFormat YMD_DASH
Format: yyyy-mm-dd. Formats the date as year, month, day with dashes delimiting the date portion. Example: 2004-12-19.


YMD_SLASH

public static final DateTimeFormat YMD_SLASH
Format: yyyy/mm/dd. Formats the date as year, month, day with slashes delimiting the date portion. Example: 2004/12/19.


YMD_DOT

public static final DateTimeFormat YMD_DOT
Format: yyyy.mm.dd. Formats the date as year, month, day with dots delimiting the date portion. Example: 2004.12.19.


YMD_NONE

public static final DateTimeFormat YMD_NONE
Format: yyyymmdd. Formats the date as year, month, day with nothing delimiting the date portion. Example: 20041219.


MDY_DASH

public static final DateTimeFormat MDY_DASH
Format: mm-dd-yyyy. Formats the date as month, day, year with dashes delimiting the date portion. Example: 12-19-2004.


MDY_SLASH

public static final DateTimeFormat MDY_SLASH
Format: mm/dd/yyyy. Formats the date as month, day, year with slashes delimiting the date portion. Example: 12/19/2004.


MDY_DOT

public static final DateTimeFormat MDY_DOT
Format: mm.dd.yyyy. Formats the date as month, day, year with dots delimiting the date portion. Example: 12.19.2004.


MDY_NONE

public static final DateTimeFormat MDY_NONE
Format: mmddyyyy. Formats the date as month, day, year with nothing delimiting the date portion. Example: 12192004.


VALUE_LIST

public static final List<DateTimeFormat> VALUE_LIST
An unmodifiable List of all the instances of DateTimeFormat.

Method Detail

getValues

public static DateTimeFormat[] getValues()
Returns an array of all the instances of DateTimeFormat. A cloned copy is returned, so no special care is required.


valueOf

public static DateTimeFormat valueOf(String name)
                              throws IllegalArgumentException
Returns the instance whose getName() method returns a String that matches the name passed in. The matching is done ignoring any case differences and after trimming any leading or trailing whitespace on the string passed in.

Parameters:
name - the name to search for.
Returns:
the matching instance
Throws:
IllegalArgumentException - if no match is found.

equals

public boolean equals(Object obj)
Overrides:
equals in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

toString

public String toString()
Overrides:
toString in class Object

compareTo

public int compareTo(DateTimeFormat other)
Specified by:
compareTo in interface Comparable<DateTimeFormat>

getName

public String getName()
Returns the name of this format. For example: YMD_HMSF_DASH, MDY_HMS_SLASH, YMD_HM_DOT, etc.


format

public StringBuffer format(Calendar cal,
                           StringBuffer appendTo)
Formats the date/time stored in the specified Calendar appending the text to the specified StringBuffer. The Calendar holds the date/time and has an associated TimeZone to define where the year, month, day, hour, etc. should be interpreted for. If the passed StringBuffer is null, then a new StringBuffer is constructed internally and returned. For a lot more flexibility, see DateTools.

Parameters:
cal - holds the date/time and the time zone to use for formatting the date/time.
appendTo - the StringBuffer to append the formatted date to. If null is passed in, then a brand new StringBuffer is created internally (and returned).
Returns:
the same StringBuffer passed in, or if null was passed in, then a new StringBuffer.
See Also:
DateTools, DateTime, DateTimeField

format

public String format(Calendar cal)
Formats the date/time stored in the specified Calendar returning the text in a String. Unlike format(Calendar, StringBuffer), this method always creates a new StringBuffer instance and a new String instance (so if you have a StringBuffer that you are already using, calling the other method is more efficient).

Parameters:
cal - the date, time, and timezone to use for formatting
Returns:
a newly created String with the formatted date/time.

ProgramixGenericLib v5.0.1

Copyright © 2001-2009 Programix Incorporated. All rights reserved. ProgramixGenericLib is free and is OSI Certified Open Source Software under the BSD license.