19 Answers. Sorted by: 227. The date difference conversion could be handled in a better way using Java built-in class, TimeUnit. It provides utility methods to do that: Date startDate = // Set start date Date endDate = // Set end date long duration = endDate.getTime () - startDate.getTime (); long diffInSeconds = TimeUnit.MILLISECONDS.toSeconds Current Date using java 8: First, let's use java.time.LocalDate to get the current system date: LocalDate localDate = LocalDate.now (); To get the date in any other timezone we can use LocalDate.now (ZoneId): LocalDate localDate = LocalDate.now (ZoneId.of ("GMT+02:30")); Indeed, if you check the Javadoc of the constructor you are mentioning, it is exactly what is suggested: Date (int year, int month, int date) Deprecated. As of JDK version 1.1, replaced by Calendar.set (year + 1900, month, date) or GregorianCalendar (year + 1900, month, date). Or use JodaTime :-). java.util.Calendar.get () method is a method of java.util.Calendar class. The Calendar class provides some methods for implementing a concrete calendar system outside the package. Some examples of Calendar fields are : YEAR, DATE, MONTH, DAY_OF_WEEK, DAY_OF_YEAR, WEEK_OF_YEAR, MINUTE, SECOND, HOUR, AM_PM, WEEK_OF_MONTH, DAY_OF_WEEK_IN_MONTH As explained in the other answers, adding both fields results in the same date, which is a bizarre implementation detail, IMO. We can see that from the source code, there's a switch statement where both fields are considered "the same" when adding: case DAY_OF_MONTH: // synonym of DATE case DAY_OF_YEAR: case DAY_OF_WEEK: Number of years will be the quotient when number of days will be divided by 365 i.e days / 365 = years. Number of weeks will be the result of (Number_of_days % 365) / 7. Number of days will be the result of (Number_of_days % 365) % 7. Below is the program implementing above approach: C++. C. mzk57.

java day of year