तिथियों से month और year निकालना
आप अपने electronics स्टोर के लिए मासिक inventory ट्रैक कर रहे हैं। date standardization लागू करके हर तारीख से month और year निकालिए!
LocalDate और DateTimeFormatter जैसे आवश्यक पैकेज आपके लिए पहले से import किए गए हैं.
यह अभ्यास पाठ्यक्रम का हिस्सा है
Java में डेटा क्लीनिंग
अभ्यास निर्देश
date1का format एक-अंकीय month/day के साथ निर्धारित करें.date2का format zero-padded month/day के साथ निर्धारित करें.date1औरdate2से month और year निकालें.
इंटरैक्टिव व्यावहारिक अभ्यास
इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।
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.____());
}
}