开发者

Does DATE format affect the way dates are compared?

开发者 https://www.devze.com 2023-02-14 06:51 出处:网络
Say I\'ve got two dates formatted this way: date1 = Feb 22, 2011 date2 = Mon Feb 21 08:30:03 EST 2011 (default formatting)

Say I've got two dates formatted this way:

date1 = Feb 22, 2011
date2 = Mon Feb 21 08:30:03 EST 2011 (default formatting)

will date2.compareTo(date1); still work? I've got a method I'm using to see if certain date values are the same, but its not 开发者_Go百科working. One date is formatted a certain way, and I think this might be problem.

Any insight would be helpful.


It will still work. The comparison is based on the milliseconds of the date. The formatting is used for display, not comparison.

In your example, check to be sure that date1 is not at 12:00:00 AM, which would be a different time than date2.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号