jnajayjain
asked on
Java code to conevrt 1 timezone to another
guys,
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.
Thanks,
Ajay.
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.
Thanks,
Ajay.
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:A M");
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
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
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.
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.
ASKER
tried with TimeStamp ts = new TimeStamp("hour:minut:ss:A M");
got compilation errors.
Myn databas is Oracle 9i.
got compilation errors.
Myn databas is Oracle 9i.
You have a typoe This is the only ctor that's usable:
http://java.sun.com/j2se/1.5.0/docs/api/java/sql/Timestamp.html#Timestamp(long)
http://java.sun.com/j2se/1.5.0/docs/api/java/sql/Timestamp.html#Timestamp(long)
following covers how to handle timezones with oracle
http://www.dbasupport.com/oracle/ora9i/TimeZone.shtml
http://www.dbasupport.com/oracle/ora9i/TimeZone.shtml
ASKER
Still did not get any clue about how using JAVA I can convert timespamp Say(Asia/Calcutta IST) to EST and vise versa.
ASKER
Can smone post any exapmle code for this.?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
:-)