BaşlayınÜcretsiz Başlayın

Extracting month and year from dates

You are tracking monthly inventory for your electronics store. Extract the month and year from each date by applying date standardization!

The necessary packages such as LocalDate, and DateTimeFormatter have been imported for you.

Bu egzersiz

Cleaning Data in Java

kursunun bir parçasıdır
Kursu Görüntüle

Egzersiz talimatları

  • Specify the format of date1 with single-digit month/day.
  • Specify the format of date2 with zero-padded month/day.
  • Extract the month and year from date1 and date2.

Uygulamalı interaktif egzersiz

Bu örnek kodu tamamlayarak bu egzersizi bitirin.

public class DateStandardizationExample {
    public static void main(String[] args) {
    	// Specify the format of date1 with single-digit month/day
    	LocalDate date1 = LocalDate.parse("1/1/23", DateTimeFormatter.ofPattern("____/____/____"));
        // Specify the format of date2 with zero-padded month/day
        LocalDate date2 = LocalDate.parse("07-01-2023", DateTimeFormatter.ofPattern("____-____-____"));
        // Extract the month and year from date1 and date2
        System.out.println("Month and year of " + date1 + ": " + date1.____() + " " + date1.____());
        System.out.println("Month and year of " + date2 + ": " + date2.____() + " " + date2.____());
    }
}
Kodu Düzenle ve Çalıştır