带T和Z的日期格式转换问题
package com.jugan; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringRunner; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; import static com.jugan.utils.LogUtils.SystemOutPrintln; @RunWith(SpringRunner.class) @SpringBootTest public class AnalysisApplicationTests { @Test public void contextLoads() {//20181023T081324Z String f0009 = "20181023T081324Z"; SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddTHHmmssZ"); SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); try { Date date = sdf.parse(f0009);//拿到Date对象 String str = sdf2.format(date);//输出格式:2018-10-23 08:13:24 System.out.println("================="+str); } catch (Exception e) { e.printStackTrace(); } } }
输出: