1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
public class Test {
public static void main(String[] args) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String dateStr = "2023-12-31 23:59:59";
try {
Date date = sdf.parse(dateStr);
String yearLowCase = sdf.format(date);
System.out.println("LowYearCase: " + yearLowCase);
SimpleDateFormat sdf2 = new SimpleDateFormat("YYYY-MM-dd HH:mm:ss");
String yearUpperCase = sdf2.format(date);
System.out.println("UpperYearCase: " + yearUpperCase);
} catch (ParseException e) {
throw new RuntimeException(e);
}
}
}
|