The hour format I use is HH:mm:ss
That is standard ISO 8601 format.
The java.time classes use ISO 8601 formats be default when parsing/generating text.
I want to convert this string into UTC+1 hour during Winter and UTC+2 during Summer.
Java includes the OffsetTime
class to represent a time-of-day with an offset-from-UTC. But this concept is faulty. Both my reading and my reasoning fail to make sense of a time with offset yet lacking a date.
I believe this class exists only to match the same idea defined by the SQL spec. Again, senseless as far as I can tell. Not the only senseless thing in the SQL spec.
To know the Date, i use the format : yyyy/MM/dd.
For data exchange, logging, and debugging, I suggest you stick with ISO 8601 format which is YYYY-MM-DD. That is like your format but using hyphen rather than slash as delimiter.
For presentation to the user, let Java automatically localize using DateTimeFormatter.ofLocalized…
methods. No point in hard-coding a format for your users.
Behind, an exemple of the kind of variable i use.
For time-of-day, use LocalTime
.
For date, use LocalDate
.
For offset, use ZoneOffset
.
For time zone, use ZoneId
.
For a moment, use the combination of LocalDate
, LocalTime
, and ZoneOffset
to get a OffsetDateTime
. Generally better to switch out offset for ZoneId
to get a ZonedDateTime
.
"14:12:13"; String Date = "2019:11:12"
LocalTime lt = LocalDate.parse( "14:12:13" ) ;
LocalDate ld = LocalDate.parse( "2019-11-12" ) ;
ZoneId z = ZoneId.of( "Africa/Tunis" ) ;
ZonedDateTime zdt = ZonedDateTime.of( ld , lt , z ) ;
This has all been covered many many many times already on Stack Overflow. So, I am being brief here. Search to learn more.