比较两个Joda-Time DateTime对象 [英] Comparing two Joda-Time DateTime objects

查看:84
本文介绍了比较两个Joda-Time DateTime对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理与此处提出的问题非常类似的事情 - 比较Joda-Time时区但它似乎对我不起作用。

I am dealing with something very similar to what has been asked here - compare Joda-Time time zones but it does not seem to work for me.

这是我正在测试的一段代码 Joda-Time DateTime with -

Here's a piece of code which I am testing Joda-Time DateTime with -

 DateTime estDT = new DateTime(DateTimeZone.forID("America/Puerto_Rico")).withMillisOfSecond(0); 
 DateTime londonDT = new DateTime(DateTimeZone.forID("Europe/London")).withMillisOfSecond(0);

    System.out.println("Comparison " + londonDT.isBefore(estDT)); 
    System.out.println("Comparison " + londonDT.isAfter(estDT)); 

有趣的是,我从上面的两个sysout语句中得到'false'。任何人都可以解释一下这种比较的正确方法吗?

Interestingly enough, I get 'false' from both the sysout statements above. Can anyone please explain what will be the right way of doing this comparison?

推荐答案

你正在创建两个可能代表同一时刻,但有不同的时区。在另一个之前或之后都没有。

You're creating two DateTime instances probably representing the same instant in time, but with different time zones. Neither is before or after the other.

时区只会影响日期/时间方法,例如 getHourOfDay()如何及时转换。

The time zone just affects how the date/time methods like getHourOfDay() convert the instant in time.

这篇关于比较两个Joda-Time DateTime对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆