KickJava   Java API By Example, From Geeks To Geeks.

Java > Java SE, EE, ME > java > text > SimpleDateFormat

java.text
Class SimpleDateFormat

java.lang.Object
  extended by java.text.Format
      extended by java.text.DateFormat
          extended by java.text.SimpleDateFormat
All Implemented Interfaces:
Serializable, Cloneable
See Also:
Top Examples, Source Code, Character.isDigit(char), Calendar, TimeZone, DateFormatSymbols

public void applyLocalizedPattern(String pattern)
See Also:
IllegalArgumentException, NullPointerException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[208]Convert String to Date object
By Anonymous on 2005/01/31 16:20:43  Rate
//Convert String to Date object 
  
  
 import java.text.SimpleDateFormat;  
 import java.util.Date;  
  
  
 public class DateFormatTest  
  {   
   public static void main (  String [  ]  cmdArgs  )   
                             throws Exception  
    {   
     SimpleDateFormat sdfInput =  
        new SimpleDateFormat (  "yyyy-MM-dd"  ) ;  
     SimpleDateFormat sdfOutput =  
        new SimpleDateFormat  (  "MM/dd/yyyy"  ) ;  
     String textDate = "2001-01-04";  
  
  
     Date date = sdfInput.parse (  textDate  ) ;  
     System.out.println (  sdfOutput.format (  date  )   ) ;  
    }  // main  
  }  // class DateFormatTest  
  
  
 //applyLocalizedPattern


public void applyPattern(String pattern)
See Also:
IllegalArgumentException, NullPointerException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public Object clone()
See Also:
Cloneable, DateFormat
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public boolean equals(Object obj)
See Also:
Hashtable, Object.hashCode(), DateFormat
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public StringBuffer format(Date date,
                           StringBuffer toAppendTo,
                           FieldPosition pos)
See Also:
NullPointerException, DateFormat
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[685]Print date
By sanimalp on 2005/07/03 16:56:40  Rate
public String printDate (  )  throws IOException, ParseException 
    {  
     String wholemessage =  ( String ) lines.get ( 1 ) ; 
            
     SimpleDateFormat input = new SimpleDateFormat ( "'Date: 'EEE, dd MMM yyyy HH:mm:ss '-0700  ( MST ) '" ) ; 
     SimpleDateFormat output = new SimpleDateFormat ( "MM/dd/yyyy hh:mm" ) ; 
     Date df = input.parse ( wholemessage ) ; 
     String date ="Date: "+output.format ( df ) ;         
      
     return date; 
  } 


[921]Parse date string with timezone
By Anonymous on 2005/02/16 05:41:28  Rate
//With Timezone 
 String dateStr = "2004-09-20 13:35:29 PDT" 
  
  
 //Watch OUT!!! SimpleDateFormat is not threadsafe 
 SimpleDateFormat sdf = new SimpleDateFormat ( "yyyy-MM-dd HH:mm:ss z" ) ; 
 java.util.Date date = sdf.parse ( dateStr ) ;


public AttributedCharacterIterator formatToCharacterIterator(Object obj)
See Also:
IllegalArgumentException, NullPointerException, Format
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public Date get2DigitYearStart()
See Also:
set2DigitYearStart(java.util.Date)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public DateFormatSymbols getDateFormatSymbols()
See Also:
setDateFormatSymbols(java.text.DateFormatSymbols)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public int hashCode()
See Also:
Hashtable, Object.equals(java.lang.Object), DateFormat
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public Date parse(String text,
                  ParsePosition pos)
See Also:
DateFormat.setLenient(boolean), NullPointerException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public void set2DigitYearStart(Date startDate)
See Also:
get2DigitYearStart()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public void setDateFormatSymbols(DateFormatSymbols newFormatSymbols)
See Also:
getDateFormatSymbols(), NullPointerException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public SimpleDateFormat()
See Also:
DateFormat
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public SimpleDateFormat(String pattern)
See Also:
IllegalArgumentException, NullPointerException, DateFormat
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[45]Format date time string
By Anonymous on 2002/10/03 13:45:40  Rate
SimpleDateFormat formatter = new SimpleDateFormat ( "yyyy-mm-dd'T'hh:mm:ss" ) ; 
 String s = formatter.format ( new Date (  )  ) ;


[342]Pay attention to the pattern, MM is different from mm
By Anonymous on 2004/03/17 18:32:40  Rate
//pay attention to the pattern, MM is different from mm 
  
  
 SimpleDateFormat sdf = new SimpleDateFormat ( "MM/dd/yyyy" ) ; 
 String serviceDate = sdf.format ( new Date (  )  ) ; 
 sdf = null; 
  
  
 System.out.println ( serviceDate ) ; 
 


[394]Parse MySQL timestamps
By RFroberg on 2003/10/27 05:56:18  Rate
SimpleDateFormat formatter = new SimpleDateFormat ( "yyyyMMddHHmmssSSS" ) ; 
  
  
 // To be run against a MySQL style timestamp, for instance 
 // 20030912211030  ( Sept. 12 2003, 21:11:10 30 millis )  
 // You can't have only two millis numbers in a SimpleDateFormat 
 // as is the case with MySQL timestamps, so we have to have 
 // three millis figures in the SimpleDateFormat and add a "0" to 
 // our MySQL timestamp, or else we'll get a parse exception: 
         Date then=null; 
         try {  
             then = formatter.parse ( ts+0 ) ;// Add a trailing "0" 
          } catch ( java.text.ParseException pe )  {  
             System.err.println ( "Parse exc.: "+pe.getMessage (  )  ) ; 
          }  
 


[1530]Format calendar
By Nicole Best (Tonic) on 2005/09/08 20:11:02  Rate
// For Calendar 
 SimpleDateFormat dateFormat = new SimpleDateFormat ( "yyyyMMdd HH:mm:ss" ) ; 
 Calendar calendar = Calendar.getInstance (  ) ;  
 System.out.println ( "Debug - > " + dateFormat.format ( calendar.getTime (  )  )  ) ; 
 


public SimpleDateFormat(String pattern,
                        DateFormatSymbols formatSymbols)
See Also:
IllegalArgumentException, NullPointerException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public SimpleDateFormat(String pattern,
                        Locale locale)
See Also:
IllegalArgumentException, NullPointerException, DateFormat
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[343]Converting date to sql date
By srinivas srmanthri75 { at } rediffmail { dot } com on 2004/08/21 07:22:11  Rate
converting date to sql date 
 SimpleDateFormat formatter = new SimpleDateFormat ( "dd-mm-yyyy" ) ; 
     String sDate = "01-02-2002"; 
  
  
     java.util.Date oDate = formatter.parse ( sDate ) ; 
     long t = oDate.getTime (  ) ; 
     java.sql.Date sqlDate = new java.sql.Date ( t ) ; 
     System.out.println ( sqlDate.toString (  )  ) ;


public String toLocalizedPattern()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[1109]_
By Anonymous on 2004/11/09 13:41:18  Rate
SimpleDateFormat format = new SimpleDateFormat ( "MM/dd/yyyy" ) ;

public String toPattern()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  

Popular Tags