Java DateFormat getTimeZone() Example
DateFormat class getTimeZone() method example. This example shows you how to use getTimeZone() method.
Syntax is : public TimeZone getTimeZone()
Method returns the time zone.
Here is the code.
/**
* @(#) GetTimeZoneDateFormat.java
* A class representing use of method getTimeZone() of DateFormat
class in java.text Package.
* @Version 12-May-2008
* @author Rose India Team
*/
import java.util.*;
import java.text.*;
class GetTimeZoneDateFormat {
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);
// getTimeZone method call.
TimeZone timeZone = dateFormat.getTimeZone();
String strTimeZone = timeZone.getDisplayName();
System.out.println("Time zone for this date format : " + strTimeZone);
}
}
|
Output of the program.
Date by Date class : Thu Jun 12 18:31:18 GMT+05:30 2008
Date by DateFormat class : 6/12/08 6:31 PM
Time zone for this date format : GMT+05:30 |
|