【发布时间】:2020-07-01 17:44:36
【问题描述】:
我正在尝试将日期解析为 LocalDateTime。
输入日期 -
{
"meetingTitle":"Test",
"fromTime":"2018-10-30 12:44",
"toTime":"2018-10-30 12:44"
}
还有 POJO -
private String meetingTitle;
@DateTimeFormat(iso = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"))
@JsonFormat(pattern = "YYYY-MM-dd HH:mm")
private LocalDateTime fromTime;
@DateTimeFormat(iso = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"))
@JsonFormat(pattern = "YYYY-MM-dd HH:mm")
private LocalDateTime toTime;
但是我得到了这个编译错误
The method ofPattern(String) is undefined for the type DateTimeFormatter
进口 -
import org.joda.time.LocalDateTime;
import org.joda.time.format.DateTimeFormatter;
import org.springframework.format.annotation.DateTimeFormat;
import com.fasterxml.jackson.annotation.JsonFormat;
我错过了来自Example 的东西吗?
【问题讨论】:
-
这个例子不是关于 joda 时间,而是关于
java.time类。所以它使用java.time.format.DateTimeFormatter