• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

java Timestamp

 
Saathvik Reddy
Ranch Hand
Posts: 228
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2988
59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20659
64
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic