I want to check if a given DateTime is before or after current
DateTime. I was converting input time and current time to a common
time zone (say UTC) and comparing DateTime. But I stumbled upon Joda
Api, hence I was curious to know if Joda is capable of doing this
without a time zone conversion. Example:
clientDateTime.isBeforeNow()
Yes, Joda DateTime comparisons with current time do not require a time zone conversion.
When comparing with current time, such as
DateTime.isBeforeNowandDateTime.isAfterNow, Joda simply compares the underlying absolute milliseconds since Jan 1, 1970. The same instant in time has exactly the same absolute milliseconds value, regardless of the timezone.For example, the instant 1355625068295 corresponds to:
Output:
And when comparing with “now”:
Output: