有 Java 编程相关的问题?

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

java是否将时间戳格式的值更改为其他时间戳格式?

嗨,有人能告诉我如何将给定的时间戳格式更改为其他时间戳格式吗 像

DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

Calendar d1 = Calendar.getInstance();
d1.setTime(formatter.parse("2012-03-08 17:32:56"));

"dd-MMM-yyyy HH:mm:ss"

格式


共 (2) 个答案

  1. # 1 楼答案

    继续^{}

    SimpleDateFormatter newFormat = new SimpleDateFormatter("dd-MMM-yyyy HH:mm:ss");
    String newFormattedDate = newFormat.format(d1);
    
  2. # 2 楼答案

    使用新的日期格式格式化日期

       DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
       Date oldFormatedDate = formatter.parse("2012-03-08 17:32:56");
       System.out.println(new SimpleDateFormat("dd-MMM-yyyy HH:mm:ss").
       format(oldFormatedDate));