Java format yyyy-MM-dd'T'HH:mm:ss.SSSz to yyyy-mm-dd HH:mm:ss
To convert a date in the format yyyy-MM-dd'T'HH:mm:ss.SSSz
to the format yyyy-mm-dd HH:mm:ss
, you can use the SimpleDateFormat
class in Java. Here's an example of how you can do it:
import java.text.SimpleDateFormat;
import java.util.Date;
public class DateFormatExample {
public static void main(String[] args) {
// Parse the input string
SimpleDateFormat inputFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSz");
Date date = inputFormat.parse("2022-03-14T16:53:01.000Z");
// Format the date according to the output string
SimpleDateFormat outputFormat = new SimpleDateFormat("yyyy-mm-dd HH:mm:ss");
String outputString = outputFormat.format(date);
System.out.println(outputString);
}
}
This will output the date as 2022-03-14 16:53:01
. Note that the mm
in the output format string should be lowercase to represent minutes, while the MM
in the input format string represents the month.