time stamp display is incorrect sometimes (database automatically changes time)

948 Views Asked by At

I have a problem with time stamp being displayed.

sometimes actual date-5.30 and other times +5.30 I do not understand how it is happening to the complete database

At one instance of time the dates are correct at second instance it is 5.30 hours ahead

I am attaching the snapshots of the two taken back to back. It is not just +/- 5.30 hrs but sometimes 11 hours ahead to actual date n time.

I had put the following code to get the IST time in database records.

BOOTSTRAP- TimeZone.setDefault(TimeZone.getTimeZone("IST")) CONFIG - JAVA_OPTS="-Duser.timezone=IST"

My server is in US and the datbase too at the same pc. I am accessing it from India. And I want the time in database to be of IST only irrespective of where ever my server may shift.Image 1Image 2

1

There are 1 best solutions below

1
On

You probably shouldn't be depending on the database, or the user.timezone setting to format your dates.

I'd suggest explicitly formatting them with a SimpleDateFormat on which you've called setTimeZone()

Here's an example: http://www.roseindia.net/java/javadate/converting-time-time-zone.shtml