Java DateFormat getDateTimeInstance() Example

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


Syntax is : public static final DateFormat getDateTimeInstance()
Method returns the date/time formatter with the default formatting style for the default locale.

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

class GetDateTimeInstanceDateFormat {

    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 that will returns default date/time.
        DateFormat dateFormat = DateFormat.getInstance();

        // getDateTimeInstance method call.
        String dFormat = dateFormat.getDateTimeInstance().format(date);
        System.out.println("Date by getDateTimeInstance method : " + dFormat);
    }
}

Output of the program.
 Date  by  Date  class : Thu Jun 12 18:19:28 GMT+05:30 2008
Date by getDateTimeInstance method : Jun 12, 2008 6:19:28 PM

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

HOME | COPYRIGHT | CONTACT US