XMLGregorianCalendar 日期比较 [英] XMLGregorianCalendar date comparison

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

问题描述

我如何比较 XMLGregorianCalendar 的 2 个实例以找出哪个更大?日期变量之一有值

How do i compare 2 instances of XMLGregorianCalendar to find which one is greater? One of the date variables have a value

date1 = 2009-02-23T05:54:17+05:30

另一个,

date2 = 2009-02-23T05:54:17.000

推荐答案

您可以将它们都转换为 GregorianCalendar 并比较它们(CalendarComparable).Calendar 的语义 compareTo() 方法是明确定义的,并且应该独立于时区工作:

You could convert them both to GregorianCalendar and compare those (Calendar is Comparable). The semantics compareTo() method of Calendar is explicitly defined, and should work independent of the timezone:

比较时间值(毫秒Epoch 的偏移量)表示为两个日历对象.

Compares the time values (millisecond offsets from the Epoch) represented by two Calendar objects.

试试这个:

XMLGregorianCalendar date1 = ...
XMLGregorianCalendar date2 = ...
int result = date1.toGregorianCalendar().compareTo(date2.toGregorianCalendar());

如果result为正,则date1date2

XMLGregorianCalendar 上的 compare() 方法本身做了一些相当奇特的事情,对我来说看起来不是很有用.

The compare() method on XMLGregorianCalendar itself does something rather peculiar, and doesn't look very useful to me.

这篇关于XMLGregorianCalendar 日期比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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