I need to convert dates in this format = "dd-M-yyyy kk:mm:ss z" to LocalDateTime as per server time. So far, I've tried every approach I could find here and on other blogs, but none helped. That's why I asked a new question.
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(SCHEDULED_TIME_FORMAT);
logger.info("Date Recieved : {}", scheduledDate);
ZonedDateTime zonedDateTime = ZonedDateTime.parse(scheduledDate, formatter);
ZonedDateTime zonedDateTimeOnMyServer = zonedDateTime.withZoneSameInstant(ZoneId.systemDefault());
LocalDateTime localDateTime = zonedDateTime.toLocalDateTime();
logger.info("Scheule Time as per Server : {}", localDateTime);
LocalDateTime scheduleTime = zonedDateTimeOnMyServer.toLocalDateTime();
logger.info("Scheduled Time as per GMT : {}", scheduleTime);
Requirement: I want localDateTime to give me the time as per Timezone provided in the string (for example, IST) and I want scheduleTime to be the time as per server.
Here are the logs of an example:
2021-10-04 13:53:53.968 INFO 1 : Date Recieved : 04-10-2021 19:24:00 IST
2021-10-04 13:53:53.972 INFO 1 : Scheule Time as per Server : 2021-10-04T19:24
2021-10-04 13:53:53.972 INFO 1 : Scheduled Time as per GMT : 2021-10-04T19:24
Please help, or suggest alternate way to achieve the requirement. A change in format is also possible but not preferred.
Update - This worked after changing "IST" to "Asia/Kolkata"