Date Methods for Legacy Java Versions

I am migrating with Java 1.1. to Java 5.

I noticed that some methods are deprecated, for example. java.util.Date has a getYear () method that is deprecated.

My question is: if the getYear () method is left as it is in 1.1, it will still function in Java 5

+6
java java-5
source share
3 answers

Yes, it will work as it did. It is entitled to uninstall only in future versions of Java SE. The leak is purely documentary and gives you a place to update the code in the meantime.

Currently, you should use either the java.util.Calendar methods or the much more advanced JodaTime APIs . Replacing the date / time API in standard Java SE will be similar to JodaTime and should still arrive ( JSR-310 ). This was planned for JDK7, but unfortunately it does not seem to be on time.

+4
source share

It will still function, even if it is outdated. They replaced it with β€œbest” (Calendar.get (Calendar.MONTH).), But the original remains there for backward compatibility. Therefore, do not use it in your case.

+4
source share

It will function, but it may not be a bad idea to start thinking about alternatives.

getYear is deprecated for some reason; the year associated with the date actually depends on the Locale and as such has been moved to the Calendar class. This remodeling of the Date class, which extracts the Locale dependency on the data itself, is what you also see in other date / calendar related functions. Thus, it may be wise to switch to Calendars where necessary.

However, I would not touch on Date / Calendar material from a java stick, I prefer things like Apache Commons Lang and others to deal with most materials related to date and time. I also heard that Yoda is popular in this regard.

+2
source share

All Articles