“Mon Aug 19 00:00:00 +0800 2024”、“Mon Aug 19 00:00:00 CST 2024” 时间字符串转时间戳:
public static void main(String[] args) {
String dateString = "Mon Aug 19 00:00:00 CST 2024";
String newDateString = fieldData.replace("CST", "+0800");// 使用 +0800 替代 CST
//"Mon Aug 19 00:00:00 +0800 2024"
SimpleDateFormat sdf = new SimpleDateFormat("EEE MMM dd HH:mm:ss Z yyyy", Locale.ENGLISH); // 使用Locale.ENGLISH
try {
// 解析字符串为 Date 对象
Date date = sdf.parse(dateString);
// 获取时间戳
long timestamp = date.getTime();
System.out.println("时间戳: " + timestamp);
} catch (ParseException e) {
e.printStackTrace();
}
}