java.util.TimeZone.getDisplayName() Method


Advertisements


Description

The getDisplayName(boolean daylight,int style) method is used to get a name of this time zone suitable for presentation to the user in the default locale.

Declaration

Following is the declaration for java.util.TimeZone.getDisplayName() method.

public final String getDisplayName(boolean daylight,int style)

Parameters

  • daylight -- if the value is true then it returns the daylight savings name.

  • style -- This is either LONG or SHORT.

Return Value

The method call returns the human-readable name of this time zone in the default locale.

Exception

  • NA

Example

The following example shows the usage of java.util.TimeZone.getDisplayName()

package com.tutorialspoint;

import java.util.*;

public class TimeZoneDemo {
   public static void main( String args[] ){
       
   // create default time zone object
   TimeZone timezonedefault = TimeZone.getDefault();
      
   // get display name
   String disname=timezonedefault.getDisplayName(true, 1); 
   
   // checking display name         
   System.out.println("Display name is :" + disname);
   }    
}

Let us compile and run the above program, this will produce the following result.

Display name is :India Daylight Time

java_util_timezone.htm

Advertisements