Java Converting Retrieved TimeStamp to Instant Gives Wrong Day

I’ve made a simple method which is used to convert a timestamp retrieved from a database into a LocalDate. However for some reason I keep getting the wrong day in the conversion. I’ve shared the code below. private LocalDate getLocalDateFromTimeStamp(Row row, String key){ return LocalDate.parse(row.getTimestamp(key).toInstant().atZome(ZoneOffset.UTC).toLocalDate().format(DateTimeFormatter.ofPattern("yyyy-MM-dd"))); } So the date I’m expecting is 2022-12-21 but what… Read More Java Converting Retrieved TimeStamp to Instant Gives Wrong Day

Read date as defined localdate from file and throw DateTimeParseException in Java

I have a problem about reading date part from txt and define them as localdate in the object. Here are example values in txt file. 1-11-2022 11-10-2022 3-12-2022 … Here is the code snippets shown below. static DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd-MM-yyyy"); … object.setDate(LocalDate.parse(objectValue[0], formatter)); // HERE IS ERROR … Here is the error shown below.… Read More Read date as defined localdate from file and throw DateTimeParseException in Java

Java LocalDate format from reading from JSON and saving to Database

In as Spring Boot app, I am reading LocalDate from a JSON in dd/MM/yyyy format e.g. 15/03/2009 and while reading, I created them to a request. The format in the request is dd/MM/yyyy. *ProductRequest: @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "dd/MM/yyyy") private LocalDate buyingDate; And then I save the date fields to database via my Entity.… Read More Java LocalDate format from reading from JSON and saving to Database

Local Date Parsing 2021-06-07+03:00

How can I parse this Date? DateTimeParseException: Text ‘2021-06-07+03:00’ could not be parsed at index 10 I have tried both DateTimeFormatter.ISO_ZONED_DATE_TIME and DateTimeFormatter.ofPattern("yyyyMMdd"). these are not work. Do u you have any suggestions? >Solution : May be something like this? String dt="2021-06-07+03:00"; DateTimeFormatter dateTimeFormatter= DateTimeFormatter.ISO_DATE; System.out.println(dateTimeFormatter.parse(dt).get(ChronoField.OFFSET_SECONDS)); System.out.println(dateTimeFormatter.parse(dt).get(ChronoField.DAY_OF_YEAR)); Output: Offset seconds: 10800 Day of year:158

I don't understand LocalDate#compareTo() Java method return value

I’m trying to get skilled on dates using them with Java and the LocalDate class, there’s something I don’t understand about the compareTo method return value, though. I thought that the nextDate.compareTo(previousDate) I’m using would return: 0 when dates are the same > 0 when the argument is before the date calling the method <… Read More I don't understand LocalDate#compareTo() Java method return value