Class SimpleDateFormat
- All Implemented Interfaces:
Cloneable
A class for parsing and formatting dates with a given pattern, compatible with the Java 6 API, as in the examples here: https://docs.oracle.com/javase/6/docs/api/java/text/SimpleDateFormat.html
To localize the formatted dates, see the discussion Format a localized date in Codename One.
-
Field Summary
-
Constructor Summary
ConstructorsConstructorDescriptionConstruct a SimpleDateFormat with no pattern.SimpleDateFormat(String pattern) Construct a SimpleDateFormat with a given pattern. -
Method Summary
Modifier and TypeMethodDescriptionvoidapplyPattern(String pattern) Apply a new pattern.clone()booleanFormat a given date.Get the date format symbols for parsing/formatting textual components of dates in a localization sensitive way.inthashCode()static booleanReturns
Parses text from a string to produce a Date.voidsetDateFormatSymbols(DateFormatSymbols newSymbols) Apply new date format symbols for parsing/formatting textual components of dates in a localisation sensitive way.static voidsetRestrictMonthNameLength(boolean restrict) Enables or disables truncating of localized month names so that they match the number of pattern characters that triggered their lookup.Returns
Methods inherited from class DateFormat
format, getDateInstance, getDateInstance, getDateTimeInstance, getInstance, getTimeInstance, getTimeInstance, parseObject
-
Constructor Details
-
SimpleDateFormat
public SimpleDateFormat()Construct a SimpleDateFormat with no pattern. -
SimpleDateFormat
Construct a SimpleDateFormat with a given pattern.
Parameters
pattern
-
-
Method Details
-
isRestrictMonthNameLength
public static boolean isRestrictMonthNameLength()Returns
- Returns:
trueif localized month names should be truncated to the requested pattern length.
-
setRestrictMonthNameLength
public static void setRestrictMonthNameLength(boolean restrict) Enables or disables truncating of localized month names so that they match the number of pattern characters that triggered their lookup.
Parameters
restrict: @param restricttrueto truncate localized month names to the length requested by the pattern,falseto keep the platform provided value as-is (default behaviour).
-
toPattern
Returns
the pattern
-
getDateFormatSymbols
Get the date format symbols for parsing/formatting textual components of dates in a localization sensitive way.
Returns
current symbols.
-
setDateFormatSymbols
Apply new date format symbols for parsing/formatting textual components of dates in a localisation sensitive way.
Parameters
newSymbols: new format symbols.
-
applyPattern
Apply a new pattern.
Parameters
pattern: the pattern to set
-
equals
- Overrides:
equalsin classDateFormat
-
hashCode
public int hashCode()- Overrides:
hashCodein classDateFormat
-
clone
- Overrides:
clonein classDateFormat
-
format
Description copied from class:DateFormatFormat a given date.
Parameters
source: date to be formatted.
Returns
formatted date.
- Overrides:
formatin classDateFormat
-
parse
Parses text from a string to produce a Date.- Overrides:
parsein classDateFormat- Throws:
ParseException
-