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 8128053
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T07:45:02+00:00 2026-06-06T07:45:02+00:00

I have a requirement where I have to convert timezone from UTC to a

  • 0

I have a requirement where I have to convert timezone from UTC to a specific timezone and vice-versa taking into account day light saving. I am using java.util.TimeZone class for it. Now, issue is that there are several hundred Ids for timezone which cannot be displayed to user.

As a work around now we have decided to have country list first and list time-zones for country selected. I am not able to get TimeZone for an ISO country code.

Here is code which I am currently using to convert timezones,

Timestamp convertedTime = null;
try{
System.out.println("timezone: "+timeZone +", timestamp: "+timeStamp);
Locale locale = Locale.ENGLISH;
        TimeZone destTimeZone = TimeZone.getTimeZone(timeZone);// TimeZone.getDefault();
        System.out.println("Source timezone: "+destTimeZone);
        DateFormat formatter = DateFormat.getDateTimeInstance(
                    DateFormat.DEFAULT,
                    DateFormat.DEFAULT,
                    locale);
        formatter.setTimeZone(destTimeZone);
        Date date = new Date(timeStamp.getTime());
        System.out.println(formatter.format(date));
        convertedTime = new Timestamp(date.getTime());
        /*long sixMonths = 150L * 24 * 3600 * 1000;
        Date inSixMonths = new Date(timeStamp.getTime() + sixMonths);
        System.out.println("After 6 months: "+formatter.format(inSixMonths));

I need to find out timezone Id to be used in above code for given country ISO code.


Update: tried many things and below code gets me to list of timezones with 148 entries (which is still large). Can any one please help me to shorten it. Or, suggest some other way to either have a shorten list of timezones or get timezones for a country,

Code:

public class TimeZones {

private static final String TIMEZONE_ID_PREFIXES =
  "^(Africa|America|Asia|Atlantic|Australia|Europe|Indian|Pacific)/.*";

private List<TimeZone> timeZones = null;

public List<TimeZone> getTimeZones() {
  if (timeZones == null) {
     initTimeZones();
  }

  return timeZones;
}

private void initTimeZones() {
  timeZones = new ArrayList<TimeZone>();
  final String[] timeZoneIds = TimeZone.getAvailableIDs();
  for (final String id : timeZoneIds) {
     if (id.matches(TIMEZONE_ID_PREFIXES)) {
        timeZones.add(TimeZone.getTimeZone(id));
     }
  }
  Collections.sort(timeZones, new Comparator<TimeZone>() {
     public int compare(final TimeZone a, final TimeZone b) {
        return a.getID().compareTo(b.getID());
     }
  });
}
  • 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-06-06T07:45:03+00:00Added an answer on June 6, 2026 at 7:45 am

    Was able to get things working. I have created own database table with all time-zones as appearing in windows OS and their corresponding TimeZone IDs. Conversion is done using java.util.TimeZone class.

    Thanks Namal and Frank for your inputs.

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

Sidebar

Related Questions

I have a specific requirement to convert a stream of bytes into a character
We have a requirement where we need to convert from .wav file to .mp3
I have a requirement to convert a date from a local time stamp to
In our project we have requirement that, after receiving sms message from third party
I have a 1GB binary file on another system. Requirement: ftp/download and convert binary
I have a requirement to convert the following types of decimal numbers to exponential
I recently moved to a project where I noticed there have a specific requirement
Basically, I have this requirement to convert a present/future weekday to a timestamp. Example:
I have a requirement in project to Convert 24 hours format to 12 hours
I have a requirement to convert the format of video to another format such

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.