I'm new to Java and have to translate a Python script using datetime
to a Java program. How do I create a Calendar
object in Java, that can have any possible year, month and day, e.g. 03.12.2050. I have to be able to add a certain amount of days to it - for example, 03.12.2050 + 29 days to get 01.01.2051 - How can I do that in Java?
It would be useful, but not necessary if the calendar class could represent Julian dates too.
You should consider using the java.time API (introduced in Java 8) - it is much better and easier to use than the legacy Calendar API.
Applied to your example, it would look like:
LocalDate d1 = LocalDate.of(2050, 12, 3);
LocalDate d2 = d1.plusDays(29); // 2051-01-01
It also supports Julian days, but not the Julian calendar, which is available in threeten-extras.