• 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

Deprecated getMonth()

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

I was using My Timestamp.getMonth() in Java 1.3.
Now, in Java 1.4.x, this method was deprectaed and replaced by Calender.get(Calender.MONTH). How to convert the Timestamp to Calender?

Regards,
Amer.
 
Ranch Hand
Posts: 704
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The Timestamp class was inheriting the method getMonth() from the java.util.Date class. This method was deprecated as of JDK version 1.1 and replaced by Calendar.get(Calendar.MONTH).
So anywhere you are calling Timestamp.getMonth() should be replaced with
Calendar.get(Calendar.MONTH).
 
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try this,

Calendar cal = new GregorianCalendar();
cal.setTime(timestamp.getTime());
cal.get(Calendar.MONTH);

Let me know if that helps....

Thanks,
Chinmay
[ October 01, 2004: Message edited by: Chinmay Bajikar ]
 
Nigel Browne
Ranch Hand
Posts: 704
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Chinmay Bajikar:
Try this,

Calendar cal = new GregorianCalendar();
cal.setTime(timestamp.getTime());
cal.get(Calendar.MONTH);

Let me know if that helps....

Thanks,
Chinmay

[ October 01, 2004: Message edited by: Chinmay Bajikar ]



That code snippet will not work because the timestamp method getTime() returns a long and the setTime() method of Calendar expects a Date as it's argument. If you replace setTime() with setTimeInMillis() the code will function as long as the timestamp object has prviously been initialised.
 
Amer Seifeddine
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks,

I think this will work with setTimeInMillis() for the cal object.
This seems to be fine.

Regards,
Amer.
 
reply
    Bookmark Topic Watch Topic
  • New Topic