YYYY vs yyyy
an anonymous user
·
Java
import java.util.*;
import java.lang.*;
import java.io.*;
import java.text.SimpleDateFormat;
import java.util.Date;
// The main method must be in a class named "Main".
class Main {
public static void main(String[] args) {
try {
String[] dates = {"2021-12-24", "2021-12-25", "2021-12-27"};
for (String date: dates) {
SimpleDateFormat dt = new SimpleDateFormat("yyyy-MM-dd");
Date d = dt.parse(date);
SimpleDateFormat dtYYYY = new SimpleDateFormat("YYYY");
SimpleDateFormat dtyyyy = new SimpleDateFormat("yyyy");
System.out.println("For date " + date + " the YYYY year is " + dtYYYY.format(d) + " while for yyyy it's " + dtyyyy.format(d));
}
} catch (Exception e) {
System.out.println("Failed with exception: " + e);
}
}
}
Output
Embed on website
To embed this program on your website, copy the following code and paste it into your website's HTML:
Comments
This comment belongs to a banned user and is only visible to admins.
This comment belongs to a deleted user and is only visible to admins.