• 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

Is it me, or have deprecated Date functions made life very difficult....

 
Ranch Hand
Posts: 301
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

I was about to write a routine that iterates through a list of objects that have a Date field.

I already a specific Date object that I wanted to compare the year and the month of items in the list with.

So my initial thought was to go through the dates and compare field1.getYear() with field2.getYear() and the month and if they match do something...

But then I see the getYear(), getMonth() etc is deprecated and it suggests to use the Calendar instead... that would result in MUCH more code and object initialisations....

Seems a silly way to do things or am I missing something here...?
 
author
Posts: 3285
13
Mac OS X Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It can be a little frustrating to use Calendar instead of date (it's one of the reasons why they're _still_ changing date time APIs in the next version of Java) but using Calendar gives you more flexibility and accuracy. An alternative you can use is an Open Source lib called Joda Time.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've never seen a need to avoid the deprecated Date methods; see here for why.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic