0

I need help setting a TimeStamp object + 1 hour. Apparently my system retrives the timestamp data -1 hour from original sql data.

I want to know if there is a quick way in Java to add 1 hour manually. Im thinking in the lines of what my code example below shows.

public boolean chooseBreak(String time, int id) throws IllegalArgumentException 
{

   Timestamp ts = Timestamp.valueOf(time);

   ts.setTime(+ 1);
Yogesh Sharma
  • 49,870
  • 5
  • 26
  • 52
JokesOnYou
  • 23
  • 6
  • 3
    I suggest not implementing a quick fix for a time zone related issue. Find out why exactly you're 1 hour off and fix the problem thoroughly. You can't `+1` all of your timestamps all the time – Lukas Eder Apr 13 '20 at 11:14
  • 1
    I recommend you don’t use `Timestamp`. That class is poorly designed and long outdated. Instead if you are having a `timestamp with time zone` in SQL, retrieve an `OffsetDateTime` from [java.time, the modern Java date and time API](https://docs.oracle.com/javase/tutorial/datetime/). If the datatype in SQL is `datetime` or `timestamp` without time zone, use `LocalDateTime`. See [my answer here](https://stackoverflow.com/a/54907501/5772882). – Ole V.V. Apr 13 '20 at 11:21
  • 1
    It’s most certainly a timezone issue. From the information in the question we cannot know the details, but you should solve the root cause of non-matching time zones, not apply a patch of adding an hour. – Ole V.V. Apr 13 '20 at 11:24

0 Answers0