0
Timestamp revsnTime = new Timestamp(System.currentTimeMillis());

I'm getting revision time in UTC but I want it in CST. How do I convert it?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Vijay
  • 3
  • 4
  • 1
    What specific `Timestamp` class are you using? Does it even represent timezones? – Louis Wasserman Apr 10 '20 at 21:48
  • 2
    If that is `java.sql.Timestamp`, I recommend you don’t use that class. It is poorly designed and long outdated. If for an SQL database, use `OffsetDateTime` from [java.time, the modern Java date and time API](https://docs.oracle.com/javase/tutorial/datetime/) for a `timestamp with time zone` (recommended for timestamp). Or if for a `timestamp` without time zone use `LocalDateTime` in Java. – Ole V.V. Apr 11 '20 at 12:18
  • 1
    Also as @LouisWassermann hinted, a `java.sql.Timestamp` does not, cannot have a time zone. Does this answer your question? [For a given Date object, capture it's value relevant to GMT timezone](https://stackoverflow.com/questions/57808424/for-a-given-date-object-capture-its-value-relevant-to-gmt-timezone) – Ole V.V. Apr 11 '20 at 14:15
  • 1
    To get the current time in Cuba Standard Time (CST): `OffsetDateTime.now(ZoneId.of("America/Havana"))`. – Ole V.V. Apr 11 '20 at 14:18

0 Answers0