0

How can I compare this timestamp format "20220708T0000Z" with current time and how can we update this timestamp to current time in same format in java, I have tried DateTimeFormatter and OffsetDateTime but both are not worked for me. Please help me. Here I am sharing my code:

private static final DateTimeFormatter formatter =       
                DateTimeFormatter.ofPattern("yyyyMMdd'T'HHmmssZ");


postEventInfoList.stream()
            .filter
                    (e -> e.getPostEventTimestamp() == null ||
                            ZonedDateTime.parse(e.getActionTimestamp(), 
        [1]formatter).isAfter(ZonedDateTime.parse(e.getPostEventTimestamp(), formatter)))
            .collect(Collectors.toList());


private void updatePostEventTimestamp(List<PostEventEntity> postEventInfoList) {
    ZonedDateTime timestamp = ZonedDateTime.now();
    
    postEventInfoList.forEach(pEvent -> {
        pEvent.setPostEventTimestamp(timestamp.format(formatter)); 
    });

enter image description here

FObersteiner
  • 22,500
  • 8
  • 42
  • 72
sravs
  • 1
  • 2
  • 1
    Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Jul 10 '22 at 13:34
  • Do not keep your timestamps in strings in `20220708T0000Z` format. Keep `Instant` objects and compare them using their `isAfter` or `isBefore` method. – Ole V.V. Jul 11 '22 at 08:50

0 Answers0