我假设您想反转日期格式?
SimpleDateFormat可用于解析和格式化。您只需要两种格式,一种解析字符串,另一种返回所需的打印输出:
SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd");Date date = fmt.parse(dateString);SimpleDateFormat fmtOut = new SimpleDateFormat("dd-MM-yyyy");return fmtOut.format(date);从Java 8开始:
DateTimeFormatter fmt = DateTimeFormatter.ofPattern("yyyy-MM-dd").withZone(ZoneOffset.UTC);TemporalAccessor date = fmt.parse(dateString);Instant time = Instant.from(date);DateTimeFormatter fmtOut = DateTimeFormatter.ofPattern("dd-MM-yyyy").withZone(ZoneOffset.UTC);return fmtOut.format(time);


