SimpleDateFormat in Java

0
111
Spread the love
  • 14
  • 34
  • 23
  • 12
  •  
  •  
  •  
  • 12
  •  
  •  
    95
    Shares

SimpleDateFormat in Java
SimpleDateFormat in Java

SimpleDateFormat in Java:

SimpleDateFormat is sub class of Format class to handle parsing and formatting of dates. We can not use the SimpleDateFormat class directly as the Date may be affected by locale. It is used mostly by DateFormat class by getting the locale info.
SimpleDateFormat class is helpful to format a specified date and time as per specified patterns for a default locale or predefined locale.
The applyPattern() method of the SimpleDateFormat clas is responsible for formatting the pattern used by an object.

The pattern table is given as:

 

On Filed Full Pattern Short Pattern
Year yyyy (4 digits) yy (2 digits)
Month MMM (Name) MM (2 digits)
M   (1/2 digits)
Day of Week EEEE EE
Day of the Month dd (2 digits) d (1/2 digits)
Day of week in month F
Day in year DDD (3 digits) D (1/2/3 digits)
Week in year ww
Era G
Timezone zzzz zz
AM/PM a
Hours [ 0-12] hh (2 digits) h (1/2 digits)
Hours [ 0-23] HH (2 digits) H (1/2 digits)
Hours [0-11] KK K
Hours [1-24] kk k
Minutes mm
Second ss
Miliseconds SSS

The Structure of SimpleDateFormat in Java is given as:


public class java.text.SimpleDateFormat extends 
             java.text.DateFormat {
//Constructors
public SimpleDateFormat();
public SimpleDateFormat(String pattern);
public SimpleDateFormat(String pattern, Locale loc);
public SimpleDateFormat(String pattern, DateFormatSymbols formatData);
//Methods
public void applyLocalizedPattern(String pattern);
public void applyPattern(String pattern);
public Object clone(); 
public boolean equals(Object obj); 
public StringBuffer format(Date date, StringBuffer toAppendTo,
FieldPosition pos);
public DateFormatSymbols getDateFormatSymbols();
public int hashCode(); 
public Date parse(String text, ParsePosition pos);
public void setDateFormatSymbols(DateFormatSymbols newFormatSymbols);
public String toLocalizedPattern();
public String toPattern();
}
 
Don't miss out!
Subscribe To Newsletter

Receive top technical news, lesson ideas, travel tips and more!

Invalid email address
Give it a try. You can unsubscribe at any time.

Spread the love
  • 14
  • 34
  • 23
  • 12
  •  
  •  
  •  
  • 12
  •  
  •  
    95
    Shares

LEAVE A REPLY

Please enter your comment!
Please enter your name here