【Date】日期格式轉換 Thu Sep 07 2017 00:00:00 GMT+0800 (中國標準時間) 00:00:00
阿新 • • 發佈:2019-02-14
/** * @Description: 將一個詭異的原始字串格式的日期改成想要的日期格式 * @author liujunran * @date 2018年1月5日 上午11:09:18 * @version V1.0 */ package test.datetest; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; /** * @author irene * */ public class OldFormat { public static void main(String[] args) throws ParseException { String dateString = "Thu Sep 07 2017 00:00:00 GMT+0800 (中國標準時間) 00:00:00"; SimpleDateFormat sdf = new SimpleDateFormat("EEE MMM dd yyyy HH:mm:ss 'GMT'Z", Locale.ENGLISH); Date dd = sdf.parse(dateString); //將字串改為date的格式 String resDate= new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").format(dd); System.out.println(resDate); } }