KickJava   Java API By Example, From Geeks To Geeks.

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

java.text
Class DateFormat

java.lang.Object
  extended by java.text.Format
      extended by java.text.DateFormat
All Implemented Interfaces:
Serializable, Cloneable
Direct Known Subclasses:
SimpleDateFormat
See Also:
Top Examples, Source Code, NumberFormat, Calendar, GregorianCalendar, TimeZone

public static final int AM_PM_FIELD
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[1411]_
By Pradeep on 2005/05/03 08:02:44  Rate
Used to identify AM or PM

protected Calendar calendar
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


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


protected DateFormat()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[539]Find difference in days between two dates
By vnpchandran77 { at } yahoo { dot } com on 2005/08/05 09:56:00  Rate
mport java.util.*;  
 import java.text.*;   
 public class Junk  {   
  
  
 public static void main ( String [  ]  args )        
      throws java.text.ParseException   {           
        
   String vGrantdate = "2002-01-07 00:00:00.0";       
   DateFormat dateFormat = new SimpleDateFormat ( "yyyy-MM-dd hh:ss:mm.SSS" ) ;       
   Date date = dateFormat.parse ( vGrantdate ) ; Date thisDate = new Date (  ) ;       
   long millisDifference = thisDate.getTime (  )  - date.getTime (  ) ;      
   long daysDifference = millisDifference /  ( 1000 * 60 * 60 * 24 ) ;          
   System.out.println ( daysDifference ) ;      
        
  }   
        
  }  
 


[1418]_
By wassam on 2005/08/05 09:55:34  Rate
I think you meant to write hh:mm:ss

public static final int DATE_FIELD
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static final int DAY_OF_WEEK_FIELD
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static final int DAY_OF_WEEK_IN_MONTH_FIELD
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static final int DAY_OF_YEAR_FIELD
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static final int DEFAULT
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


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


public static final int ERA_FIELD
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public final StringBuffer format(Object obj,
                                 StringBuffer toAppendTo,
                                 FieldPosition fieldPosition)
See Also:
Format
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[613]Format a date to yyyy-MM-dd hh:mm:ss.SSS
By Anonymous on 2005/06/06 08:50:25  Rate
import java.text.SimpleDateFormat; 
 import java.util.Date; 
                                                                                                                 
 public class Date_format  {  
     public static void main ( String [  ]  args )   {  
         SimpleDateFormat sdf; 
         Date time = new Date (  ) ; 
         sdf = new SimpleDateFormat ( "yyyy-MM-dd hh:mm:ss.SSS" ) ; 
         String date = sdf.format ( time ) ; 
         System.out.println ( date ) ; 
      }  
  }  
 


[849]Parse and format a date
By david wang (lwang10 { at } yahoo { dot } com) on 2005/08/02 03:01:15  Rate
String notifyDates = "8/3/2004"; 
 Calendar calendar = Calendar.getInstance (  ) ; 
 DateFormat dateFormat = new SimpleDateFormat ( "MM/dd/yyyy" ) ; 
      
 try {  
   Date date = dateFormat.parse ( notifyDates ) ;     
   calendar.setTime ( date ) ; 
   System.out.println ( "The initial date is : " + dateFormat.format ( calendar.getTime (  )  )  ) ; 
   calendar.add ( Calendar.DATE, 30 ) ; 
   System.out.println ( "The date in 30 days is : " + dateFormat.format ( calendar.getTime (  )  )  ) ; 
  } catch ( Exception e )  {  
   e.printStackTrace (  ) ; 
  } 


public final String format(Date date)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public abstract StringBuffer format(Date date,
                                    StringBuffer toAppendTo,
                                    FieldPosition fieldPosition)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static final int FULL
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static Locale[] getAvailableLocales()
See Also:
Locale.US
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


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


public static final DateFormat getDateInstance()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static final DateFormat getDateInstance(int style)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static final DateFormat getDateInstance(int style,
                                               Locale aLocale)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[1786]
By Rao P on 2006/07/10 22:13:39  Rate
 
 // use to display time of the client for different time zone  
 // getting client locale 
  < % 
   java.util.Locale locale = request.getLocale (  ) ; 
   
   // get Dateformat for client's locale 
   java.text.DateFormat dateFormat = 
    java.text.DateFormat.getDateTimeInstance (  
      java.text.DateFormat.LONG, 
      java.text.DateFormat.LONG, locale ) ; 
  % > 


public static final DateFormat getDateTimeInstance()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static final DateFormat getDateTimeInstance(int dateStyle,
                                                   int timeStyle)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static final DateFormat getDateTimeInstance(int dateStyle,
                                                   int timeStyle,
                                                   Locale aLocale)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static final DateFormat getInstance()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


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


public static final DateFormat getTimeInstance()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static final DateFormat getTimeInstance(int style)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static final DateFormat getTimeInstance(int style,
                                               Locale aLocale)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


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


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


public static final int HOUR0_FIELD
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static final int HOUR1_FIELD
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static final int HOUR_OF_DAY0_FIELD
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static final int HOUR_OF_DAY1_FIELD
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


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


public static final int LONG
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static final int MEDIUM
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static final int MILLISECOND_FIELD
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static final int MINUTE_FIELD
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static final int MONTH_FIELD
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


protected NumberFormat numberFormat
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public Date parse(String source)
           throws ParseException
See Also:
parse(String, ParsePosition)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[81]Format a date and get year, month, day part of a date
By Anonymous on 2005/03/09 07:41:44  Rate
import java.util.*; 
 import java.text.*;  
 public class Junk  {  
  
  
 public static void main ( String [  ]  args )       
      throws java.text.ParseException   {          
       
   String vGrantdate = "2002-01-07 00:00:00.0";      
   DateFormat dateFormat = new SimpleDateFormat ( "yyyy-MM-dd hh:ss:mm.SSS" ) ;      
   Date date = dateFormat.parse ( vGrantdate ) ; Date thisDate = new Date (  ) ;      
   long millisDifference = thisDate.getTime (  )  - date.getTime (  ) ;     
   long daysDifference = millisDifference /  ( 1000 * 60 * 60 * 24 ) ;         
   System.out.println ( daysDifference ) ;     
       
  }  
       
  } 


[390]_
By Anonymous on 2003/11/14 16:24:22  Rate
SimpleDateFormat sdf = new SimpleDateFormat ( "dd-MMM-yyyy" ) ; 
 java.util.Date aDate = sdf.parse ( "9-Sep-03" ) ; 
 


[817]_
By dleothomas { at } yahoo { dot } com on 2004/06/23 00:29:44  Rate
GregorianCalendar gc = new GregorianCalendar (  ) ; 
     gc.setLenient ( false ) ; 
     String vGrantdate = dateJoined;         
     DateFormat dateFormat = new SimpleDateFormat ( "MM-dd-YYYY" ) ;        
     Date myDate = dateFormat.parse ( vGrantdate ) ;     
      
     gc.set ( GregorianCalendar.YEAR, myDate.getMonth (  )  ) ; 
     gc.set ( GregorianCalendar.MONTH, myDate.getDate (  )  ) ; // invalid month 
     gc.set ( GregorianCalendar.DATE,myDate.getYear (  )  ) ;


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


public Object parseObject(String source,
                          ParsePosition pos)
See Also:
NullPointerException, Format, parse(String, ParsePosition)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static final int SECOND_FIELD
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public void setCalendar(Calendar newCalendar)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public void setLenient(boolean lenient)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[295]Returns a util date from the date string passed, based on the format string
By Anonymous on 2005/02/09 07:18:45  Rate
/** 
  * Returns a util date from the date string passed, based on the format string. 
  */
 
 public static Date getUtilDate (  String _dateString, String _formatString  )  
  {  
     try  {  
  
  
        // Format the current time. 
        SimpleDateFormat formatter = new SimpleDateFormat (  _formatString  ) ; 
  
  
        formatter.setLenient  ( false ) ; 
  
  
        Date javaDate = formatter.parse  (  _dateString  ) ; 
  
  
        return javaDate; 
  
  
      }  catch  ( Exception e )  {  
  
  
         return null; 
  
  
      }  
  
  
   } 


public void setNumberFormat(NumberFormat newNumberFormat)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public void setTimeZone(TimeZone zone)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[908]Getting the Simple Date Formatter to display a time in another timezone
By Anonymous on 2004/09/20 08:51:28  Rate
SimpleDateFormat sdf = new SimpleDateFormat ( "HHmmss" ) ; 
 TimeZone tz = TimeZone.getTimeZone ( "GMT" ) ; 
  
  
 Calendar day1 = Calendar.getInstance ( tz ) ; 
 Date day2 = new Date (  ) ; 
 day2.setHours ( 9 ) ; 
 day1.setTime ( day2 ) ; 
 sdf.setTimeZone ( tz ) ; //reset the Timezone, since it does not carry from first date 
  
  
 String resultTime = sdf.format ( day1.getTime (  )  ) ;


[1184]_
By Anonymous on 2005/02/02 11:36:10  Rate
// Getting the Simple Date Formatter to display a time in another timezone 
     Calendar cal = Calendar.getInstance (  ) ; 
     SimpleDateFormat sdf = new SimpleDateFormat ( "HH:mm:ss MM/dd/yyyy" ) ; 
     System.out.println ( sdf.format ( cal.getTime (  )  )  ) ; 
     sdf.setTimeZone ( TimeZone.getTimeZone ( "GMT" )  ) ; 
     System.out.println ( sdf.format ( cal.getTime (  )  )  ) ;


public static final int SHORT
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static final int TIMEZONE_FIELD
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static final int WEEK_OF_MONTH_FIELD
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static final int WEEK_OF_YEAR_FIELD
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static final int YEAR_FIELD
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  

Popular Tags