Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7058031
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:03:51+00:00 2026-05-28T04:03:51+00:00

Hi I want to get Time Zone from locale. My code is package com.my.country;

  • 0

Hi I want to get Time Zone from locale. My code is

    package com.my.country;

    import java.text.DateFormat;
    import java.util.ArrayList;
    import java.util.Date;
    import java.util.Locale;
    import java.util.Map;
    import java.util.StringTokenizer;
    import java.util.TimeZone;
    import android.app.Activity;
    import android.os.Bundle;
    import android.util.Log;
    import android.view.View;
    import android.widget.AdapterView;
    import android.widget.AdapterView.OnItemSelectedListener;
    import android.widget.ArrayAdapter;
    import android.widget.Spinner;
    import android.widget.TextView;

    public class StoreCountry extends Activity 
   {
String countryname="";
Spinner spinnerAvailableID,availableCurrencycode;
TextView textTimeZone,countrycodetxt;
ArrayAdapter<String> timeAdapter,codeAdapter;

   @Override

   public void onCreate(Bundle savedInstanceState) {

   super.onCreate(savedInstanceState);

   setContentView(R.layout.select);

   String selectString = getString(R.string.select);

   spinnerAvailableID = (Spinner)findViewById(R.id.availableID);
   availableCurrencycode = (Spinner)findViewById(R.id.availablecurrency);

   textTimeZone = (TextView)findViewById(R.id.timezone);
  countrycodetxt = (TextView)findViewById(R.id.countrycode);


   ArrayList<String> timeArray = new ArrayList<String>();
   timeArray.add(selectString);
   String[] idArray = TimeZone.getAvailableIDs();
   for(int i=0;i<idArray.length;i++)
   {
       String mycon=idArray[i];
       timeArray.add(mycon);
   }
   System.out.println(timeArray);
   timeAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, timeArray);
   timeAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
   spinnerAvailableID.setAdapter(timeAdapter);
   spinnerAvailableID.setOnItemSelectedListener(new OnItemSelectedListener()
   {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view,int position, long id) 
        {
            String selectedId = (String)(parent.getItemAtPosition(position));
            System.out.println(selectedId);
            TimeZone tz = TimeZone.getTimeZone(selectedId);
            String timezone=TimeZone.getTimeZone(tz.getID()).getDisplayName(false,TimeZone.SHORT);
            String timezonename=TimeZone.getTimeZone(tz.getID()).getDisplayName(false,TimeZone.LONG);
            Log.d("Tag","TimeZone : "+timezone+"\t"+timezonename);
            textTimeZone.setText(timezone+"\t"+timezonename);

            DateFormat df = DateFormat.getTimeInstance();
            df.setTimeZone(TimeZone.getTimeZone(timezone));
            String gmtTime = df.format(new Date());
            System.out.println(gmtTime);

            StringTokenizer st2 = new StringTokenizer(selectedId,"/");  
            while(st2.hasMoreTokens())
            {
                countryname= st2.nextToken();
                System.out.println(countryname);
                break;
            }


        }
        @Override
        public void onNothingSelected(AdapterView<?> arg0)
        {
            // TODO Auto-generated method stub

        }});


   ArrayList<String> codeArray=new ArrayList<String>();
   codeArray.add(selectString);
   CurrencySymbol cs = new CurrencySymbol();
   Map<String, String> currencies = cs.getAvailableCurrencies();
   for (String country : currencies.keySet()) 
   {      
       String currencyCode = currencies.get(country);
       codeArray.add(currencyCode);
       System.out.println(country + " => " + currencyCode);
   }       
   codeAdapter= new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, codeArray);
   codeAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
   availableCurrencycode.setAdapter(codeAdapter);
   availableCurrencycode.setOnItemSelectedListener(new OnItemSelectedListener()
   {
    @Override
    public void onItemSelected(AdapterView<?> parent1, View view1, int position1,long id1) 
    {
        String selectedCode = (String)(parent1.getItemAtPosition(position1));
        System.out.println(selectedCode);
        countrycodetxt.setText(selectedCode);
    }

    @Override
    public void onNothingSelected(AdapterView<?> arg0) 
    {       

    }     });

   /*ArrayList<String> countryArray = new ArrayList<String>();
   timeArray.add(selectString);*/


   Locale[] myCountry = Locale.getAvailableLocales();
   for(int i=0;i<myCountry.length;i++)
   {
       Locale mycon=myCountry[i];

       String name1=mycon.getDisplayName();
       //timeArray.add(mycon);
      // String name=mycon.getDisplayCountry(mycon);

       System.out.println("locale name--->"+mycon);
       //System.out.println("country name--->"+name);
       System.out.println("country name =--->"+name1);

       TimeZone time = TimeZone.getTimeZone(name1);
        String timezone=TimeZone.getTimeZone(time.getID()).getDisplayName(false,TimeZone.SHORT);
        System.out.println("time zone"+timezone);
      // String time=mytime.getDisplayName();
     //  System.out.println("time zone---->"+mytime);
   }


}
}

But it doesn’t work. If i convert Locale value into String value means is it work?
And how to convert this? And is it possible to get Time Zone? Can anybody tell me. Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T04:03:52+00:00Added an answer on May 28, 2026 at 4:03 am

    Most applications will use getDefault() which returns a TimeZone based on the time zone where the program is running.

    You can also get a specific TimeZone by id.

    See here for more information.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to get clients Time Zone offset from his IP address for my
I want to get the time zone from the Android mobile when clicking a
In my code, I need to get the time zone of Venezuela from Registry.
i want to get current time (now) from Different time zone . for example
In symfony 2 controllers, every time I want to get a value from post
I want to get time from database then use it to compare with current
I get the current NSDate in the user time zone with the following code
I want get the time used for a case so I can create an
I want to get the last modified time of any part of a view
Every time I open a page I want to get the currently active project

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.