Join
Blogs
Questions
Videos
Tags
Members
Search
 
 
Create your own blog, earn points and get popular!

Java SimpleDateFormat Example

  1. /*
  2. Java SimpleDateFormat example.
  3. This Java SimpleDateFormat example describes how class is defined
  4. and being used in Java language.
  5.  
  6. */
  7.  
  8. import java.text.SimpleDateFormat;
  9. import java.util.Date;
  10.  
  11. public class JavaSimpleDateFormatExample{
  12.    
  13.     public static void main(String args[]){
  14.        
  15.         // Create Date object        
  16.         Date date = new Date();
  17.        
  18.         //Specify the desired date format        
  19.         String DATE_FORMAT = "MM/dd/yyyy";
  20.        
  21.         //Create object of SimpleDateFormat and pass the desired date format        
  22.         SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT);
  23.        
  24.         /*
  25.         Use format method of SimpleDateFormat class to format the date.
  26.         */
  27.        
  28.         System.out.println("Today is " + sdf.format(date));
  29.    
  30.     }
  31.  
  32. }
  33.  
  34. /*
  35. OUTPUT of the above given Java SimpleDateFormat Example would be:
  36. Today is 02/06/2005
  37. */
Your rating: None Average: 2.6 (8 votes)
Share this