Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Comparing Dates of Two different timezones.  RSS feed

 
Ankit Pradhan
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
I need to write a Java logic which would tell whether two dates are equal or not. The problem is that the two dates which i am getting is in the String format from somewhere.
e.g.
These dates are equal (that is known)
"15-SEP-06 10.27.31.436332 AM +05:30"
"14-SEP-06 10.57.31.436213 PM -06:00"

But what Java logic i should write which compare these type of dates and let me know in terms of interger(-1, 0, 1) if they are equal or not.

Please respond ASAP.
I have tried the solution like compare(..) but somehow the timezone trick is missing.

Thanks in advance.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well Dates are just millisecond values, and changing timezone can't change that value. All the compareTo method in the Date class does ultimately is just get the millisecond value of the date and do a simple long comparison.


I have tried the solution like compare(..) but somehow the timezone trick is missing.


I'm going to guess that your problem is not the Date compareTo method, but how you turn your String values into Date objects. You'll need a DateFormat that matches the format of the timezone your Date String uses, otherwise you'll parse the date incorrectly.

(Also, not really an advanced question, so I'm moving this to a more appropriate forum.)
[ September 15, 2006: Message edited by: Paul Sturrock ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!