有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!


共 (1) 个答案

  1. # 1 楼答案

    如果您正在使用java.util.Date

    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);
    

    这是一个遗留软件包,建议使用以下代码

    如果您正在使用java.time.*

    DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("dd.MM.yy");
    LocalDate unformattedDate = LocalDate.parse("your date here", dateTimeFormatter);
    
    dateTimeFormatter = DateTimeFormatter.ofPattern("dd/MM/yy");
    String formattedDate = dateTimeFormatter.format(unformattedDate);
    

    我会对你的模式做如下改变。我不使用y,而是使用u,因为它也包括ADBC

    例如:dd/MM/uu

    有关更多信息,请参阅this