[英]Runtime exception while parsing date in linux system (Working fine in windows system)
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 上面的代码在Windows系统中运行正常,但是在Linux系统中,它
java.time.format.DateTimeParseException
运行时异常: java.time.format.DateTimeParseException
:无法解析文本'Fri Sep 14 18:16:13 BST 2018':null
The problem is likely because your Linux system is using a non-English Locale, ie Friday is not named Fri
. 该问题可能是因为您的Linux系统使用的是非英语语言环境,即星期五未命名为
Fri
Explicitly specify the locale: 明确指定语言环境:
DateTimeFormatter.ofPattern("E MMM dd HH:mm:ss z yyyy", Locale.UK);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.