SimpleDateFormat dateTimeFormatter = new SimpleDateFormat("dd.MM.yy");
Date unformattedDate = dateTimeFormatter.parse("your date here");
dateTimeFormatter = new SimpleDateFormat("dd/MM/yy");
String formattedDate = dateTimeFormatter.format(unformattedDate);
# 1 楼答案
如果您正在使用
java.util.Date
:这是一个遗留软件包,建议使用以下代码
如果您正在使用
java.time.*
我会对你的模式做如下改变。我不使用
y
,而是使用u
,因为它也包括AD
和BC
例如:
dd/MM/uu
有关更多信息,请参阅this