一、CST格式字符串转换成yyyy-MM-dd HH:mm:ss格式的时间
1、java代码
String dateStr = "Mon Oct 26 15:19:15 CST 2020";
DateFormat cstFormate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
DateFormat gmtFormate = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy", Locale.ENGLISH);
Date dateTime = gmtFormate.parse(dateStr);
String dateString = cstFormate.format(dateTime);
System.out.println(dateString);
2、转换结果
2020-10-26 15:19:15
二、CST格式的日期转换为GMT时间
1、java代码
// Mon Oct 26 16:05:53 CST 2020
Date date = new Date();
DateFormat gmtDateFormat = new SimpleDateFormat("EEE, d-MMM-yyyy HH:mm:ss z", Locale.ENGLISH);
gmtDateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
String dateStr = gmtDateFormat.format(date);
System.out.println(dateStr);
2、转换结果
Mon, 26-Oct-2020 08:05:53 GMT