SimpleDateFormat


SimpleDateFormat java.text

Java 1.1 cloneable serializable

This is the concrete Format subclass used by DateFormat to handle the formatting and parsing of dates. Most applications should not use this class directly; instead, they should obtain a localized DateFormat object by calling one of the static methods of DateFormat .

SimpleDateFormat formats dates and times according to a pattern, which specifies the positions of the various fields of the date, and a DateFormatSymbols object, which specifies important auxiliary data, such as the names of months. Applications that require highly customized date or time formatting can create a custom SimpleDateFormat object by specifying the desired pattern. This creates a SimpleDateFormat object that uses the DateFormatSymbols object for the default locale. You may also specify an locale explicitly, to use the DateFormatSymbols object for that locale. You can even provide an explicit DateFormatSymbols object of your own if you need to format dates and times for an unsupported locale.

You can use the applyPattern( ) method of a SimpleDateFormat to change the formatting pattern used by the object. The syntax of this pattern is described in the following table. Any characters in the format string that do not appear in this table appear literally in the formatted date.

Field

Full form

Short form

Year

yyyy (4 digits)

yy (2 digits)

Month

MMM ( name )

MM (2 digits), M (1 or 2 digits)

Day of week

EEEE

EE

Day of month

dd (2 digits)

d (1 or 2 digits)

Hour (1-12)

hh (2 digits)

h (1 or 2 digits)

Hour (0-23)

HH (2 digits)

H (1 or 2 digits)

Hour (0-11)

KK

K

Hour (1-24)

kk

k

Minute

mm

 

Second

ss

 

Millisecond

SSS

 

AM/PM

a

 

Time zone

zzzz

zz

Day of week in month

F (e.g., 3rd Thursday)

 

Day in year

DDD (3 digits)

D (1, 2, or 3 digits)

Week in year

ww

 

Era (e.g., BC/AD)

G

 

Figure 15-16. java.text.SimpleDateFormat

 public class  SimpleDateFormat  extends DateFormat {  // Public Constructors  public  SimpleDateFormat  ( );        public  SimpleDateFormat  (String  pattern  );        public  SimpleDateFormat  (String  pattern  , java.util.Locale  locale  );        public  SimpleDateFormat  (String  pattern  , DateFormatSymbols  formatSymbols  );  // Public Instance Methods  public void  applyLocalizedPattern  (String  pattern  );        public void  applyPattern  (String  pattern  );  1.2  public java.util.Date  get2DigitYearStart  ( );        public DateFormatSymbols  getDateFormatSymbols  ( );  1.2  public void  set2DigitYearStart  (java.util.Date  startDate  );        public void  setDateFormatSymbols  (DateFormatSymbols  newFormatSymbols  );        public String  toLocalizedPattern  ( );        public String  toPattern  ( );  // Public Methods Overriding DateFormat  public Object  clone  ( );        public boolean  equals  (Object  obj  );        public StringBuffer  format  (java.util.Date  date  , StringBuffer  toAppendTo  ,          FieldPosition  pos  );        public int  hashCode  ( );        public java.util.Date  parse  (String  text  , ParsePosition  pos  );  // Public Methods Overriding Format   1.4  public AttributedCharacterIterator  formatToCharacterIterator  (Object  obj  );   } 



Java In A Nutshell
Java In A Nutshell, 5th Edition
ISBN: 0596007736
EAN: 2147483647
Year: 2004
Pages: 1220

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net