import java.time.LocalDateTime;
final java.time.format.DateTimeFormatter formatter =
java.time.format.DateTimeFormatter.ofPattern("E MMM dd HH:mm:ss z yyyy");
final LocalDateTime dateTime1 = LocalDateTime.parse("Fri Sep 14 18:04:03 BST 2018", formatter)
The above code is working fine in Windows system but in Linux system its throwing Runtime exception : java.time.format.DateTimeParseException
: Text 'Fri Sep 14 18:16:13 BST 2018' could not be parsed: null
The problem is likely because your Linux system is using a non-English Locale, ie Friday is not named Fri
.
Explicitly specify the locale:
DateTimeFormatter.ofPattern("E MMM dd HH:mm:ss z yyyy", Locale.UK);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.