To format a date string in the format yyyy-MM-dd'T'HH:mm:ss.SSSz to the format yyyy-MM-dd HH:mm:ss, you can use the java.time package introduced in Java 8. Here's how you can do it:
import java.time.Instant; import java.time.ZoneId; import java.time.format.DateTimeFormatter; public class DateTimeFormatExample { public static void main(String[] args) { // Input date string in the format yyyy-MM-dd'T'HH:mm:ss.SSSz String inputDateString = "2023-11-14T13:45:30.123Z"; // Define a DateTimeFormatter for the input format DateTimeFormatter inputFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSX"); // Parse the input date string into an Instant Instant instant = Instant.from(inputFormatter.parse(inputDateString)); // Define a DateTimeFormatter for the desired output format DateTimeFormatter outputFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); // Convert the Instant to a desired time zone (e.g., UTC) and format it String outputDateString = instant.atZone(ZoneId.of("UTC")).format(outputFormatter); // Print the formatted date string System.out.println(outputDateString); } } In this code:
yyyy-MM-dd'T'HH:mm:ss.SSSz.DateTimeFormatter (inputFormatter) to parse this input format.Instant.DateTimeFormatter (outputFormatter) for the desired output format yyyy-MM-dd HH:mm:ss.Instant to the desired time zone (e.g., UTC) using atZone() and then format it using the outputFormatter.Make sure to adjust the time zone (ZoneId.of(...)) to your specific requirements if needed.
linear-algebra html-encode rollupjs delicious-api android-viewmodel java-7 nsfetchrequest fragmenttransaction next-images admin