converting GMT format String to Datetime in spring boot Java

My Mongo Input Source data is 2020-04-14 00:00:00.0000000 (GMT-04:00), 
Data Type String
Error: Caused by: java.time.format.DateTimeParseException: Text '' could not be parsed at index 0
at java.time.format.DateTimeFormatter.parseResolved0(DateTimeFormatter.java:1949) ~[na:1.8.0_222]

I did:

Command.java:

DateTimeFormatter dateTimeformatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); 
List<RatingTiming> response = repo.findByserviceRequestedTimestampBetween(LocalDateTime.parse(query.getStartvalue(), dateTimeformatter), LocalDateTime.parse(query.getEndvalue(), dateTimeformatter));

Mogorepo.java :

public interface RatingResponseRepository extends MongoRepository<RatingTiming, String> {
    List<RatingTiming> findByserviceRequestedTimestampBetween(LocalDateTime startDate, LocalDateTime endDate);
}

Json.java :

@JsonFormat
(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss'")
@JsonDeserialize(using = DateDeserializer.class)
@JsonProperty("serviceRequestedTimestamp")
public LocalDateTime serviceRequestedTimestamp;


Read more here: https://stackoverflow.com/questions/66229268/converting-gmt-format-string-to-datetime-in-spring-boot-java

Content Attribution

This content was originally published by Bsr at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: