Java DateFormat getInstance() Example

DateFormat class getInstance() method example. This example shows you how to use getInstance() method.


Syntax is : public static final DateFormat getInstance()
Method returns a default date/time formatter that uses the SHORT style for both the date and the time.

Here is the code.
/**
 * @(#) GetInstanceDateFormat.java
 * A class representing use of method getInstance() of DateFormat
class in java.text Package.
 * @Version  12-May-2008
 @author   Rose India Team
 */
import java.util.*;
import java.text.*;

class GetInstanceDateFormat {

    public static void main(String[] args) {

        // Create new Date object that will be initialized to the current date.
        Date date = new Date();
        System.out.println("Date  by  Date  class    : " + date.toString());

        // Create new DateFormat object by getInstance method.
        DateFormat dateFormat = DateFormat.getInstance();
        String stringDate = dateFormat.format(date);
        System.out.println("Date by DateFormat class : " + stringDate);
    }
}

Output of the program.
 Date  by  Date  class    : Thu Jun 12 18:21:38 GMT+05:30 2008
Date by DateFormat class : 6/12/08 6:21 PM

Post Comment
Name:
E-mail:
Contact no :
Comments:
  Refresh Image
Verify Image:
 
 
Your Comment's
 
 
 

HOME | COPYRIGHT | CONTACT US