web123456

The problem of converting into various formats in java

yyyy-MM-dd’T’HH:mm:

The three SSSs below refer to milliseconds, Z represents the time zone, and T in the middle represents any replacement character.

Let's see the example below:
Example 1:

@Test
    public void testTime() throws ParseException{
       Date date = new Date(); 
       SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:");
       SimpleDateFormat df1 = new SimpleDateFormat("yyyy-MM-dd'test'HH:mm:"); 
       String str = df.format(date);
       String str1 = df1.format(date);     
       System.out.println(str);
       System.out.println(str1);     
    }

Test results

2017-06-08T10:41:06.261+0800
2017-06-08Test 10:41:06.261+0800

Example 2:

Convert 2017-05-18T10:26:10.488Z into yyyy-MM-dd HH:mm:ss or yyyyMMddHHmmss format

@Test
    public void testTime1() throws ParseException{
       String dateStr = "2017-05-18T10:26:10.488Z";
       SimpleDateFormat dff = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:",);//The converted time format entered
       SimpleDateFormat df1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//The time format required to be converted into
       SimpleDateFormat df2 = new SimpleDateFormat("yyyyMMddHHmmss");
       Date date1 = (dateStr);     
       String str1 = (date1);
       String str2 = (date1);
       System.out.println("str1 is "+str1);
       System.out.println("str2 is "+str2);
    }

Running results:

str1 is 2017-05-18 10:26:10
str2 is 20170518102610

All the above tests: There is no deception.