简体   繁体   English

将转换符合ISO8601的日期与Java日期进行比较?

[英]Comparing Converting ISO8601-compliant date with Java date?

As per this question , I have found how to parse the Solr date, but I am still unable to compare it with Java date. 根据这个问题 ,我已经找到了如何解析Solr日期,但是我仍然无法将其与Java日期进行比较。

DateTimeFormatter parser2 = ISODateTimeFormat.dateTimeNoMillis();
    String jtdate = "2010-01-01T12:00:00+01:00";
    System.out.println(parser2.parseDateTime(jtdate));

Currently I have got date in this format : 2013-07-28T13:48:02Z and I need to apply compareTo() operator on this date with current date from Java. 目前,我有以下格式的日期:2013-07-28T13:48:02Z,我需要在该日期将此应用带有Java中的当前日期的compareTo()运算符。

Assuming you do not care about the time, consider using DateTimeComparator.getDateOnlyInstance() , which is a Comparator that ignores the time fields when making the comparison, eg: 假设您不关心时间,请考虑使用DateTimeComparator.getDateOnlyInstance() ,它是一个Comparator ,在进行比较时会忽略时间字段,例如:

final DateTime a = parser2.parseDateTime(jtdate);
final Date b = new Date();

DateTimeComparator comparator = DateTimeComparator.getDateOnlyInstance();
comparator.compare(a, b);

Or, 要么,

comparator.compare(a, DateTime.now());

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM