Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

java.sql.ResultSet getTimestamp Locale issue

 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am using getTimeStamp(column index, calander function)

In the specs its mentioned - This method uses the given calendar to construct an appropriate millisecond value for the timestamp if the underlying database does not store timezone information.

Is that Calander time zone parameter only works if the database does not store timezone information?

I am trying to retrive data using Locale.

In database my date is 2005-05-15 15:00:00. I am running my Local web server in CST time zone.

When I retrive value from database using Pacific time zone, I am getting same date and time.
rs.getTimestamp(5, cal) --> 2005-05-15 15:00:00.0

Even without using timezone, I am getting same result
rs.getTimestamp(5) --> 2005-05-15 15:00:00.0
 
Marshal
Posts: 28288
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

When I retrive value from database using Pacific time zone

And how exactly do you do that? And for that matter, how do you retrieve data using a Locale? I have always used SQL to retrieve data. Clarification would help.
 
Mukesh Mittal
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am retriving data from sybase database using JDBC.

rs.getTimestamp(field index, Cal)

In Cal I setup pacific TimeZone. Without timezone and with timezone, system is giving me the same result.
 
Paul Clapham
Marshal
Posts: 28288
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Then that suggests to me that the database already knows the timezone of the timestamp it's returning to you and doesn't require your assistance.

If you want to display a timestamp as if it were in some other timezone, then just get a SimpleDateFormat object and call its setTimeZone() method.

And there is no relationship between Locale and TimeZone.
 
Mukesh Mittal
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the explaination.

I am trying to use time without using SimpleDateFormat. My impression is that, SimpleDateFormat is basically use for Display purpose.

I want to change time using PST or any other time zone for further processing. What's the purpose of setting timezone in calendar and then set date in that?

TimeZone t = TimeZone.getDefault();
t = TimeZone.getTimeZone("EST");

java.util.Calendar cal = java.util.Calendar.getInstance(t);

java.util.Date date = new java.util.Date();
cal.setTime(new java.sql.Timestamp(date.getTime()));


What's the purpose of setting timezone in java.util.Calendar?
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic