Java – Creating a Date object with an offset in Java


I'm currently learning how to create applications for Android, but my Java is quite rusty as I'm more of a .NET person.

If in C#, I wanted to create a DateTime object with the value set to todays date plus 5 years, I could use

DateTime dt = DateTime.Now.AddYears(5);

Is there something similar to this in the Java language?

Best Solution

You could use a Calendar to do the calculation:

Calendar cal = Calendar.getInstance();
cal.add(Calendar.YEAR, 5);
Date date = cal.getTime(); // getTime() returns a Date object