• Post Reply Bookmark Topic Watch Topic
  • New Topic

Deprecated getMonth()  RSS feed

 
Amer Seifeddine
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • 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.
 
Nigel Browne
Ranch Hand
Posts: 704
  • Mark post as helpful
  • send pies
  • 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).
 
Chinmay Bajikar
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • Quote
  • Report post to moderator
Thanks,

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

Regards,
Amer.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!