public class TLcdSymbologyDateFormat extends Format
java.util.Date
objects and
Strings formatted as "ddHHmmssTMMMyy"
, with T being a timezone character, and the
other characters specified in SimpleDateFormat
.
The format uses UTC ('Z', or zulu time) by default, but this can be
changed
.
Example usage:
TLcdSymbologyDateFormat format = new TLcdSymbologyDateFormat();
Date date = new Date();
String formattedDate = format.format( date );
System.out.println( "date = " + date );
System.out.println( "formattedDate = " + formattedDate );
// Example output:
// date = Tue Oct 01 14:27:36 CEST 2013
// formattedDate = 01122736ZOCT13
Format.Field
Constructor and Description |
---|
TLcdSymbologyDateFormat()
Creates a new symbology date format for the UTC timezone.
|
TLcdSymbologyDateFormat(String aFormatString)
Creates a new symbology date format for the UTC timezone according to the provided format string.
|
Modifier and Type | Method and Description |
---|---|
StringBuffer |
format(Object obj,
StringBuffer toAppendTo,
FieldPosition pos) |
TimeZone |
getTimeZone()
Returns the timezone that is used when formatting a date.
|
boolean |
isWithSeconds()
Returns if the seconds are formatted/parsed.
|
Object |
parseObject(String source,
ParsePosition pos) |
void |
setTimeZone(TimeZone aTimeZone)
Sets the timezone to use when formatting a Date.
|
void |
setWithSeconds(boolean aWithSeconds)
Sets if the seconds should be formatted.
|
clone, format, formatToCharacterIterator, parseObject
public TLcdSymbologyDateFormat()
setWithSeconds(boolean)
to be able to format "ddHHmmssMMMyy" which has seconds data.
To provide custom formats you can use TLcdSymbologyDateFormat(String)
setTimeZone(java.util.TimeZone)
public TLcdSymbologyDateFormat(String aFormatString)
<pattern> ::= <day>[<separator>]<hour>[<separator>]<minute>[<separator>][<second>][<separator>]<timezone>[<separator>]<month>[<separator>]<year> <day> ::= "dd" <hour> ::= "HH" <minute> ::= "mm" <second> ::= "ss" <timezone> ::= "T" <month> ::= "MMM" <year> ::= "yy" <separator> ::= ":" | "-" | "."All the elements are mandatory except <second> and <separator>. One can change the placement of the elements as well. Typical examples are;
Note that when you use this constructor, setWithSeconds(boolean)
will have no effect.
aFormatString
- format stringsetTimeZone(java.util.TimeZone)
public TimeZone getTimeZone()
public void setTimeZone(TimeZone aTimeZone)
aTimeZone
- a time zonepublic boolean isWithSeconds()
TLcdSymbologyDateFormat(String)
this value has no effect on formatting.public void setWithSeconds(boolean aWithSeconds)
false
.
Note that this has no effect on parsing.
Format.parseObject(String)
accepts string with or without seconds regardless of this property.aWithSeconds
- true
if the seconds should be formatted/parsed.public StringBuffer format(Object obj, StringBuffer toAppendTo, FieldPosition pos)
public Object parseObject(String source, ParsePosition pos)
parseObject
in class Format