• Post Reply Bookmark Topic Watch Topic
  • New Topic

java.util.Date.setYear() deprecated  RSS feed

 
kri shan
Ranch Hand
Posts: 1489
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator



Prints current date, time with current year. But setYear() and getYear() of java.util.Date are deprecated. Any other way ?
 
Junilu Lacar
Sheriff
Posts: 11168
160
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you looked at the JavaDocs? When something is deprecated in the API there's usually an accompanying note in the JavaDocs about what to use instead. I'd bet there's one that can help you in this case.
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16028
87
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use class java.util.Calendar instead, or better, if you are using Java 8, use the classes from the java.time package instead of the old java.util.Date and java.util.Calendar classes.
 
Bobby Kiran
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use the Calendar object instead of Date



and you can convert your Calendar object back to Date object
 
Campbell Ritchie
Marshal
Posts: 55793
164
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!