| 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: 1150
|
|
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: 19216
|
|
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
How To Ask Questions How To Answer Questions
|
 |
 |
|
|
subject: java Timestamp
|
|
|