I have date in this format yyyy-MM-dd'T'HH:mm:ss'Z', but while i'm parsing this using OffsetDateTime.parse(date); it returns the string by elimination seconds
Logic : Get the day from date, if it is Saturday or Sunday change day to monday and return the date String
String date = "2018-12-30T06:00:00Z";
System.out.println(date);
try {
OffsetDateTime dateTime = OffsetDateTime.parse(date);
System.out.println(dateTime); //2018-12-30T06:00Z
DayOfWeek day = dateTime.getDayOfWeek();
// check if price change date is Sunday or Saturday and change it to Monday
if (day.equals(DayOfWeek.SATURDAY) || day.equals(DayOfWeek.SUNDAY)) {
String finalDateTime = dateTime.with(TemporalAdjusters.next(DayOfWeek.MONDAY)).toString();
System.out.println(finalDateTime); //2018-12-31T06:00Z
}else {
System.out.println(date);
}
}catch(Exception ex) {
System.out.println(ex);
System.out.println(date);
}
I need to return string as same input format yyyy-MM-dd'T'HH:mm:ss'Z'