• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

I need some dating advice

 
Mike Southgate
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've created some classes that get dates from an xml file. I'm using Date() to store the data and SimpleDateFormat to parse it.

I then need to add a number of seconds to the Date and compare it to another Date. Right now I'm using GregorianCalendar.add() and then converting back to a Date. I then use Date.after to compate them.

This all seems a bit complex to me. Might I not be further ahead to store the dates as longs, then simply add (seconds * 1000)? I could compare directly and would only need to treat them as dates on first reading them from the xml, and when displaying to the users.

what is the best practice here?

ms
 
Greg T Robertson
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you're converting from a date to a calendar already - why not just compare the calendar objects (before/after). As a word of warning (because I got nailed by it recently), depending upon how you are reading your dates from XML, database, etc - you have to be careful of TimeZones because your dates can lose some hours. IMHO it's easiest to parse the date field as a Calendar from the XML, then always use Calendar for everything (add, and compares). Of course I'm using JAXB which reads dates from XML as Calendar (at least for the fields I'm using).
 
Gaurav Saxena
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dating advice? Go to msn personlas or yahoo personals dude!!... Just kidding. Yeah i agree with whatever Greg said.It's best to use GregorianCalendar for Date related functions.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic