File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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: 2173
    
  47
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: 19653
    
  18

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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: java Timestamp
 
Similar Threads
java.util.Calendar
Question on Gregorian Calendar
SpinnerDateModel
!SimpleDateFormat
GregorianCalendar