• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

Comparing Dates of Two different timezones.

 
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.
 
Bartender
Posts: 10336
Hibernate Eclipse IDE 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 ]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic