user1609085
user1609085

Reputation:

compare Joda-Time time zones

In my application using Joda-Time, I need to compare two time stamps (either DateTime or LocalDateTime)...if t1.isBefore(t2) then allow the user else pop up an error...

say, I have t1 as 2013-03-01T10:17:55.872 (always US/EASTERN -0500 or -0400 Standard offset)

but, my t2 will change depedning on the location of the user and I can get the offset as well as time, say t2 as 2013-03-01T14:48:09.000 and offset of -0800.

How can compare these two using 'isBefore'?

any suggestion is appreciated!

Upvotes: 1

Views: 1753

Answers (1)

Jon Skeet
Jon Skeet

Reputation: 1499770

Well, if you have them both as DateTime values, you should just be able to use isBefore, as DateTime inherits that from AbstractInstant.

However, I'd be quite tempted to convert them plain Instant values first (via toInstant). That way it's clearer that you don't care about the local date/time; you're only interested in the instants they represent. (I'm assuming that really is the kind of comparison you want. If you actually want to compare the local date/time, convert both to LocalDateTime instead!)

Upvotes: 4

Related Questions