I have a Timestamp object in which the value is written

<DateTimeCalc>2019-03-18T03:00:00+03:00</DateTimeCalc> 

How to do so in order to understand that GMT is an empty time of 00:00:00 GMT, that is, without an offset, in order to handle this case?

 public boolean isManualCalc(Timestamp timestamp) { return timestamp.getHours() == 0 && timestamp.getMinutes() == 0 && timestamp.getSeconds() == 0; } 

But, this code does not consider offsets. How to extract offset from timestamp so that timestamp.getHours () - the shift returned zero?

Potentially I can send values

 <DateTimeCalc>2019-03-18T02:00:00+02:00</DateTimeCalc> <DateTimeCalc>2019-03-18T05:00:00+05:00</DateTimeCalc> 

and so on

    2 answers 2

    Try this:

    Timestamp aa = new Timestamp (); aa.getDate (). getTimezoneOffset ()

    Taken from: https://docs.oracle.com/javase/7/docs/api/java/sql/Timestamp.html Methods inherited from class java.util.Date

      In general, the Timestamp does not contain a time shift! But if you receive a string with a time shift, then this is what you can do:

       ZonedDateTime zdt = ZonedDateTime.parse("2019-03-18T03:00:00+03:00"); // Дата и время с учетом зоны GMT LocalDateTime gmt = LocalDateTime.ofInstant(zdt.toInstant(), ZoneId.of("GMT")); 

      And then look at the hours, minutes, seconds, etc. ...

      If you still want to use your method with the Timestamp parameter:

       ZonedDateTime zdt = ZonedDateTime.parse("2019-03-18T03:00:00+03:00"); TimeZone.setDefault(TimeZone.getTimeZone("UTC")); Timestamp timestamp = Timestamp.from(zdt.toInstant()); System.out.println("isManualCalc(timestamp) = " + isManualCalc(timestamp));