I cannot convert the date containing GMT to timestamp in Java
Here is the code shown below
import java.sql.Timestamp;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
public class DataParser {
public static void main(String[] args) throws ParseException {
String startDate = "Mon May 01 2023 00:00:00 GMT 0300 (GMT 03:00)";
SimpleDateFormat inputFormat = new SimpleDateFormat("EEE MMM dd yyyy HH:mm:ss 'GMT' X (zzzz)");
SimpleDateFormat outputFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date parsedDate = inputFormat.parse(startDate);
String formattedDate = outputFormat.format(parsedDate);
Timestamp timestamp = Timestamp.valueOf(formattedDate);
System.out.println(timestamp);
}
}
Here is the error shown below
Exception in thread "main" java.text.ParseException: Unparseable date: "Mon May 01 2023 00:00:00 GMT 0300 (GMT 03:00)"
at java.base/java.text.DateFormat.parse(DateFormat.java:399)
at example1.DataParser.main(DataParser.java:17)
How can I fix it?
Here is my answer shown below
Here is the output shown below