Java DateFormat getDateInstance() Example
DateFormat class getDateInstance() method example. This example shows you how to use getDateInstance() method.
Syntax is : public static final DateFormat getDateInstance()
Method returns the date formatter with the default formatting style for the default locale.
Here is the code.
/**
* @(#) GetDateInstanceDateFormat.java
* A class representing use of method getDateInstance() of DateFormat
class in java.text Package.
* @Version 12-May-2008
* @author Rose India Team
*/
import java.util.*;
import java.text.*;
class GetDateInstanceDateFormat {
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();
// getDateInstance method call.
String dFormat = dateFormat.getDateInstance().format(date);
System.out.println("Date instance of this date format : " + dFormat);
}
} |
Output of the program.
Date by Date class : Thu Jun 12 18:11:18 GMT+05:30 2008
Date instance of this date format : Jun 12, 2008 |
|