Yyyy-mm-dd ' T ' HH:mm:ss. Sssz
The following three SSS refer to milliseconds, Z represents the time zone, and the middle T represents any replaceable character.
Here's a look at the example:
Example One:
@Test public
void Testtime () throws parseexception{
Date date = new Date ();
SimpleDateFormat df = new SimpleDateFormat ("Yyyy-mm-dd ' T ' HH:mm:ss. Sssz ");
SimpleDateFormat df1 = new SimpleDateFormat ("Yyyy-mm-dd ' Test" HH:mm:ss.) Sssz ");
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-08 Test 10:41:06.261+0800
Example Two:
Convert 2017-05-18t10:26:10.488z to 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:ss.") SSS ", Locale.english)//converted time format of input
SimpleDateFormat df1 = new SimpleDateFormat (" Yyyy-mm-dd HH:mm:ss "); The time format needed to be converted
SimpleDateFormat df2 = new SimpleDateFormat ("Yyyymmddhhmmss");
Date date1 = Dff.parse (DATESTR);
String str1 = Df1.format (date1);
String str2 = Df2.format (date1);
System.out.println ("str1 is" +str1);
System.out.println ("str2 is" +str2);
}
Run Result:
STR1 is 2017-05-18 10:26:10
str2 is 20170518102610
All of the above are Pro test: Fair trade.