compare Joda-Time time zones

余生颓废 提交于 2019-12-24 14:35:59

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!