• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

I need some dating advice

 
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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).
 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic