DateTime myDateTime = new DateTime(); int year = myDateTime.getYear(); System.out.println("Year is " + year);
DateTime myDateTime = new DateTime("2021-06-30"); int year = myDateTime.getYear(); System.out.println("Year is " + year);This code creates a new DateTime object with a specific date of June 30, 2021, and then retrieves the year value using the getYear() method. Finally, it prints the year to the console. In both examples, the code uses the org.joda.time package and the DateTime class to work with dates and times.