wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes java Timestamp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "java Timestamp" Watch "java Timestamp" New topic
Author

java Timestamp

Saathvik Reddy
Ranch Hand

Joined: Jun 03, 2005
Posts: 228
I want to get month and year from the timestamp.

Ex: Timestamp timestamp = new Timestamp(new Date().getTime());

I am using timestamp.getMonth() and timestamp.getYear() to get month and date but both the methods are deprecated.
What methods should i use instead of these deprecated methods?

Thanks,
Srikanth.
Tony Docherty
Bartender

Joined: Aug 07, 2007
Posts: 2301
    
  49
You should use a Calendar object.

You can obtain one for your locale, set it to the timestamp's time and use it as follows:

Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19697
    
  20

And remember to compare the month against the month constants: Calendar.JANUARY - Calendar.DECEMBER. That way you won't get that confused when you notice that the months are 0-based


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
GeeCON Prague 2014
 
subject: java Timestamp