0

I've seen on other posts that the root cause of my issue is time zones and the fact Timestamp.valueOf() uses time zones. How do I get valueOf to use the correct time zone?

This java test fails:

public void runTimestampTest()
{
    String timeString = "2019-03-10 02:01:33.242000";
    Timestamp timestamp = Timestamp.valueOf(timeString);
    System.out.println("timeString = " + timeString);
    System.out.println("timestamp  = " + timestamp);

    assertEquals(timeString, timestamp.toString());
}

the timestamp I get is "2019-03-10 03:01:33.242". When I get the default time zone it's 'America/Denver'. If I iterate all time zones and get the zone with raw offset equal to the ZONE_OFFSET I get 'America/Boise'. How do I get these to match? TimeZone.setDefault() doesn't fix it.

I can't seem to get a timestamp with the correct value and I have to use a Timestamp class to pass to another API.

Thanks, -Mike

Mike_G
  • 149
  • 2
  • 9
  • Possible duplicate of [TimeStamp.valueOf() method](https://stackoverflow.com/questions/49809816/timestamp-valueof-method) – ᴇʟᴇvᴀтᴇ Oct 03 '19 at 19:56
  • There are 2 differences between timeString and timestamp. One is the hour, the other is the microsecond, which one is incorrect as your expectation? Or both? – LHCHIN Oct 04 '19 at 01:11
  • It's the hour difference that's incorrect. – Mike_G Oct 04 '19 at 12:51
  • I've seen responses like the link above. The solution is always to use the new Java time but we use other APIs that use a timestamp so I can't simply move to using an Instant and it's in production code that would require a great deal of refactoring to move to the newer APIs. I've been trying to find a way to fin the time zone being use by the Timestamp class and set so I don't get the offset but haven't been able to find a way to do this. – Mike_G Oct 04 '19 at 12:54

0 Answers0