将 html datetime-local 类型输入解析为 java LocalDateTime

FeC*_*eCH 2 java datetime jsp

代码

JSP:

<div class="col-md-4 col-sm-6 col-xs-12">
    <fmt:formatDate value="${sighting.sightingDateAsDate}" var="sightingDateString" pattern="yyyy-MM-dd'T'hh:mm:ss"/>
    <sf:input type="datetime-local" class="add-form form-control" path="sightingDate" value="${sightingDateString}"/>
</div>

Controller:

String sightingDateString = request.getParameter("sightingDate");
LocalDateTime sightingDate = LocalDateTime.parse(sightingDateString.replace("T"," "), DateTimeFormatter.ISO_DATE_TIME);
Run Code Online (Sandbox Code Playgroud)

我正在处理这个编辑表单。fmt:formatDate 是将sightingDate 转换为html 可读的格式,因此输入字段datetime-local 将填充现有的LocalDateTime 值。

现在的问题是将其转换回 LocalDateTime。我得到的当前错误是:

错误

Request processing failed; nested exception is 
java.time.format.DateTimeParseException: Text '2017-03-22 01:00' could not be parsed at index 10
Run Code Online (Sandbox Code Playgroud)

我也试过没有替换(“T”,“”)。错误会说 Text '2017-03-22T01:00' 而不是 Text '2017-03-22 01:00'

lib*_*ban 6

DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'hh:mm");
Date date = (Date)formatter.parse(sightingDateString); 
Run Code Online (Sandbox Code Playgroud)

谢谢