Java code to conevrt 1 timezone to another


can someone post any java code/help to converting one timezone to another.

I want to develop a small utility where user can select timezone and time (hour:minut:ss:AM) and then when he submits the page, timestamp should be converted to US EST and saved in database. Later on when same info is retrieved (from database in EST) should be dispalyed in USER'S DEFAULT TIME ZONE (PC'S SET TIMEZONE) on fronend.

Also want to know if "TimeZone.getDefault()" is the correct way to know the user's default timezone.

Need to include the daylight saving time also.

any help will be greatly appreciated.



Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Date is actually quite free of TimeZone information. All you need to do is to save the user's TimeZone then apply it later to the date formatting
TimeStamp ts =  new TimeStamp("hour:minut:ss:AM");

and now converting it into US EST depends what time zone you entered

look at the TimeStamp API and you can modify the hours accordingly

then you store in the database


I think you want to display the same time that was stored in the database ( not the current time )
In that case, add or remove the hours according to the Timezone
java.sql.Timestamp is also free of TimeZone information and should be formatted according to the user's time zone
Angular Fundamentals

Learn the fundamentals of Angular 2, a JavaScript framework for developing dynamic single page applications.

Mick BarryJava DeveloperCommented:
Best would be to store the date in UTC, let me know what database you are using and will let you know what you need.
You can then display it in any timezone once retrieved.

> TimeZone.getDefault()

you can set use the default timezone, another option is to set the timezone of the SimpleDateFormat used to display the date once retrieved.
jnajayjainAuthor Commented:
tried with TimeStamp ts =  new TimeStamp("hour:minut:ss:AM");
got compilation errors.

Myn databas is Oracle 9i.
You have a typoe This is the only ctor that's usable:
Mick BarryJava DeveloperCommented:
following covers how to handle timezones with oracle
jnajayjainAuthor Commented:
Still did not get any clue about how using JAVA I can convert timespamp Say(Asia/Calcutta IST) to EST and vise versa.
jnajayjainAuthor Commented:
Can smone post any exapmle code for this.?
Mick BarryJava DeveloperCommented:
Timestamp class does not have a timezone associated with it. Only a Calendar instance does and it has a method to set the timezone

Or you can set the timezone of the formatter used to format the toimezone

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
>>Timestamp class does not have a timezone associated with it.

I already mentioned that earlier.

What you need first of all is to establish your mechanism for saving the user's time zone in the first place and then secondly you need to retrieve it. Saving their locale would be useful as well for formatting purposes. When you've done that, as i mentioned earlier:

>>then apply it later to the date formatting

// (if saved locale == US and TimeZone == CET)
              DateFormat df = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL, Locale.US);
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.