Alireza
Alireza

Reputation: 6868

How to have date comparison in Scala LocalDateTime?

I have datetime string in the format of 2019-07-21T00:00. And also I get the current datetime using:

from_date = "2019-07-21T00:00"

// 2020-02-10T16:40:53.146
LocalDateTime.now().toString

What I want to do is to check whether given date-time is bigger than current date-time. How can I compare the above two date-times?

Upvotes: 0

Views: 1688

Answers (1)

mfirry
mfirry

Reputation: 3692

Try parsing it first and then comparing it using the built-in methonds in LocalDateTime

Something along these lines:

LocalDateTime.parse(from_date).isAfter(LocalDateTime.now)

Upvotes: 1

Related Questions