public class SimpleDateFormat extends Object
Symbol Meaning Presentation Example ------ ------- ------------ ------- y year (Number) 1996 M month in year (Text & Number) July & 07 d day in month (Number) 10 h hour in am/pm (1~12) (Number) 12 H hour in day (0~23) (Number) 0 m minute in hour (Number) 30 s second in minute (Number) 55 S millisecond (Number) 978 E day in week (Text) Tuesday a am/pm marker (Text) PM z GMT TimeZone (Text & Number) GMT+04:00 Z RFC 822 Time Zones (Number) -0400 ' escape for text
Modifier and Type | Field and Description |
---|---|
static int |
OPTION_PARSE_MISSING_TIME_ZONE_TO_DEFAULT
An option to parse(String,Calendar,options).
|
static int |
OPTION_PARSE_MISSING_TIME_ZONE_TO_GMT
An option to parse(String,Calendar,options).
|
Constructor and Description |
---|
SimpleDateFormat(String format)
Create a SimpleDateFormat using the specified format and the default
Locale.
|
SimpleDateFormat(String format,
Locale locale)
Create a SimpleDateFormat using the specified format and the default
specified Locale.
|
Modifier and Type | Method and Description |
---|---|
static LocaleFormat |
fixLocaleFormat(LocaleFormat src,
LocaleFormat dest)
Copy to the dest LocaleFormat the data from the LocaleFormat src
adjusting the values such that the locale field is valid, the
format field is a String or is null and the options field is zero.
|
String |
format(Calendar c)
Format the date specified in the Calendar as a String.
|
String |
format(Date date)
Deprecated.
use format(java.util.Calendar) instead.
|
String |
format(Time t)
Format the date specified in the Time as a String.
|
String |
format(Time t,
TimeZone tz)
Format the date specified in the Time as a String.
|
String |
getFormat()
Returns the format.
|
Locale |
getLocale()
Get the Locale used for the SimpleDateFormat.
|
int |
hashCode()
Returns a hashCode for the object.
|
static void |
main(String[] args) |
Date |
parse(String str)
Deprecated.
use parse(String str, Calendar destination) instead.
|
Calendar |
parse(String str,
Calendar dest,
int options)
Parse the String using this Object's formatting.
|
Time |
parse(String str,
Time dest)
Parse the String using this Object's formatting.
|
Object |
parseObject(String str)
Deprecated.
use parse(String str, Calendar destination) instead.
|
protected int |
parseTimeZoneOffset(String src,
int startPosition,
SimpleTimeZone destination)
This is used to parse a String for the TimeZone offset value.
|
void |
setLocale(Locale locale)
Set the Locale used for the SimpleDateFormat.
|
LocaleFormat |
toLocaleFormat(LocaleFormat dest)
Convert this to a LocaleFormat.
|
String |
toString()
Returns the format.
|
public static final int OPTION_PARSE_MISSING_TIME_ZONE_TO_DEFAULT
public static final int OPTION_PARSE_MISSING_TIME_ZONE_TO_GMT
public SimpleDateFormat(String format)
format
- the format string to use.public void setLocale(Locale locale)
locale
- the Locale to use.public Locale getLocale()
public LocaleFormat toLocaleFormat(LocaleFormat dest)
dest
- an optional destination LocaleFormat.public static LocaleFormat fixLocaleFormat(LocaleFormat src, LocaleFormat dest)
src
- the source LocaleFormat.dest
- the destination LocaleFormat.public String toString()
public String getFormat()
public int hashCode()
Object
public Object parseObject(String str) throws ParseException
str
- the String to parse.ParseException
- if the string is badly formatted.public Date parse(String str) throws ParseException
str
- the String to parse.ParseException
- if the string is badly formatted.protected int parseTimeZoneOffset(String src, int startPosition, SimpleTimeZone destination) throws ParseException
You can override this if you want to change how TimeZones are parsed.
src
- the source String.startPosition
- the starting index in the String.destination
- the non-null destination SimpleTimeZone. Call
setRawOffset() to set the raw offset.ParseException
- if the TimeZone is missing or badly formatted.public Calendar parse(String str, Calendar dest, int options) throws ParseException
str
- the String to parse.dest
- an optional destination Calendar. If it is null a new
one is created and returned.options
- the OPTION_PARSE_XXX values OR'ed together.ParseException
- if the String was not properly formatted for
the date.public Time parse(String str, Time dest) throws ParseException
str
- the String to parse.dest
- an optional destination Time. If it is null a new
one is created and returned.ParseException
- if the String was not properly formatted for
the date.public String format(Date date)
date
- the Date to format.public String format(Calendar c)
c
- the date in the Calendar.public String format(Time t)
t
- the date in the Time.public String format(Time t, TimeZone tz)
t
- the date in the Time.tz
- the TimeZone for the Time.public static void main(String[] args) throws ParseException
ParseException