The pattern you are using does not match the one of the String. Your pattern cannot parse a two-digit month first because the String starts with an abbreviated day of week, whose abbreviation even depends on the Locale, which you haven't specified, so it will take the system default.
However, you can try to parse it with a different pattern, but I don't think it will get you the desired result… Try DateTimeFormatter.ofPattern("EEE MMM dd HH:mm:ss z uuuu", Locale.ENGLISH) instead of your DateTimeFormatter.ofPattern("MM/dd/yyyy") and see the result. On my machine, it assumes IST to be Iceland Standard Time!
See this example:
public static void main(String[] args) {
// example String
String toBeParsed = "Fri Sep 30 00:00:00 IST 2022";
// first formatter: tries to parse "IST" as ZONE TEXT
DateTimeFormatter dtfZ = new DateTimeFormatterBuilder()
.appendPattern("EEE MMM dd HH:mm:ss")
.appendLiteral(' ')
.appendZoneText(TextStyle.SHORT)
.appendLiteral(' ')
.appendPattern("uuuu")
.toFormatter(Locale.ENGLISH);
// second formatter: tries to parse "IST" as ZONE NAME
DateTimeFormatter dtfz = DateTimeFormatter.ofPattern(
"EEE MMM dd HH:mm:ss z uuuu",
Locale.ENGLISH
);
// parse to a ZonedDateTime with the first formatter
ZonedDateTime zdt = ZonedDateTime.parse(toBeParsed, dtfZ);
// print the result
System.out.println("ZonedDateTime: "
+ zdt.format(DateTimeFormatter.ISO_ZONED_DATE_TIME));
// parse to a ZonedDateTime with the second formatter
ZonedDateTime zdt2 = ZonedDateTime.parse(toBeParsed, dtfz);
// print that, too
System.out.println("ZonedDateTime: "
+ zdt2.format(DateTimeFormatter.ISO_ZONED_DATE_TIME));
// convert to an Instant
Instant instant = zdt.toInstant();
// print the epoch millis
System.out.println(instant.toEpochMilli());
}
Output:
ZonedDateTime: 2022-09-30T00:00:00Z[Atlantic/Reykjavik]
ZonedDateTime: 2022-09-30T00:00:00Z[Atlantic/Reykjavik]
1664496000000
If you want the LocalDate.atStartOfDay()
, you could simply extract it by calling toLocalDate()
on an instance of ZonedDateTime
(in case that ZonedDateTime
contains any time of day different from zero hours, minutes, seconds and further down the units).