且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Java-将yyyy-MM-dd'T'HH:mm:ssZ转换为可读的dd-MM-yyyy

更新时间:2023-02-26 14:02:02

是。它可以分为两部分,如下所示:

Yes. It can be done in two parts as follows:


  1. 解析您的 String Date 对象

SimpleDateFormat sd1 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
Date dt = sd1.parse(myString);


  • Date 对象的格式设置为所需格式

  • Format the Date object to desirable format

    SimpleDateFormat sd2 = new SimpleDateFormat("yyyy-MM-dd");
    String newDate = sd2.format(dt);
    System.out.println(newDate);
    


  • 您将不得不使用两个不同的 SimpleDateFormat ,因为两种日期格式不同。

    You will have to use two different SimpleDateFormat since the two date formats are different.

    输入:

    2015-01-12T10:02:00+0530
    

    输出:

    2015-01-12