How can I change timezone of a java.sql.Timestamp object which was initially, instantiated to CST, to GMT?
How can I change timezone of a java.sql.Timestamp object which was initially, instantiated to
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
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.
java.sql.Timestampobjects don’t have time zones – they are instants in time, likejava.util.Date.If you’re thinking of them as being in a particular time zone, you may either be getting confused due to misleading output (e.g. something automatically converting that instant into a local time using a default time zone) or you may have created the data in an inappropriate way. The answer you need will depend on the details of your situation.
For example, if you just want to display a
Timestampvalue in a particular time zone, you can useSimpleDateFormat, set the time zone appropriately, and just format theTimestamp(as it extendsDate). I don’t believe that will allow you to display as much precision as the timestamp stores internally, but that may not be a problem for you.If your data has been created incorrectly then there may or may not be a way to “correct” it – there may be some ambiguities due to daylight saving time changes, for example. However, the more we know about it the better we’ll be able to help you.