jodd.datetime.formatters
Class DefaultFormatter

java.lang.Object
  extended byjodd.datetime.formatters.DefaultFormatter
All Implemented Interfaces:
JdtFormatter

public class DefaultFormatter
extends java.lang.Object
implements JdtFormatter

Default formatter used for getting and setting date/time information to and from strings.

For setting date and time, default formatter parses input String against specified template. It extracts parts of input string upon patterns and then each part is converted to a number for a date/time information. It doesn't ignore any non-number charater. If conversion fails, null is returned. Translations from String are done by Java.

Getting date time is also user firendly. Specified template may not only contains patterns but also any text. To remove errors in decoding when text may be reckognized as one of patterns, template text may be quoted with the ' sign. Double ' quote in the text will be decoded as single quote.

Bellow is the list of the patterns that may be used in templates. This list enhances ISO 8601 standard. Patterns notted with + sign are used for settings, all patterns are used for gettings.


Constructor Summary
DefaultFormatter()
           
 
Method Summary
 java.lang.String get(JDateTime jdt, java.lang.String frmt)
          Returns date as String in given format.
 DateTimeStamp set(java.lang.String s, java.lang.String t)
          Sets time from the string using template.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultFormatter

public DefaultFormatter()
Method Detail

get

public java.lang.String get(JDateTime jdt,
                            java.lang.String frmt)
Returns date as String in given format. Used by JDateTime for formatting the string that represents date/time information.

Specified by:
get in interface JdtFormatter
Parameters:
jdt - JDateTime instance
frmt - format
Returns:
date string in given format

set

public DateTimeStamp set(java.lang.String s,
                         java.lang.String t)
Sets time from the string using template. Used by JDateTime for setting new date/time from the string. But it is also used for validating if some string represents a valid date.

Specified by:
set in interface JdtFormatter
Parameters:
s - String that contains time
t - template
Returns:
DateTimeStamp instance or null if error during conversion occured


Jodd v0.24.5 Javadoc