问题
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!
回答1:
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!)
来源:https://stackoverflow.com/questions/15165788/compare-joda-time-time-zones