在Android 12和13中,日期格式的默认设置与之前版本不同。在以前的版本中,日期格式为“yyyy-MM-dd”,但在Android 12和13中,日期格式为“yyyy/MM/dd”。
为了解决这个问题,您可以在您的应用程序中明确指定日期格式。您可以使用SimpleDateFormat类来创建自定义日期格式。以下是一个示例代码:
String date = "2022-12-30";
SimpleDateFormat originalFormat = new SimpleDateFormat("yyyy-MM-dd");
SimpleDateFormat newFormat = new SimpleDateFormat("yyyy/MM/dd");
try {
Date convertedDate = originalFormat.parse(date);
String formatedDate = newFormat.format(convertedDate);
System.out.println(formatedDate);
} catch (ParseException e) {
e.printStackTrace();
}
在上面的代码中,我们首先将日期字符串“2022-12-30”转换为日期对象,然后将其格式化为新的日期格式“yyyy/MM/dd”。这将生成字符串“2022/12/30”。
您可以将此示例代码嵌入您的应用程序中,以确保在Android 12和13中正确显示日期格式。