我试图解析日期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;
难道我错过了一些例子?
该DateTimeFormatter.ofPattern
方法是一部分java.time
的API,这是比jodatime更好(由同一人撰写的,事后,由jodatime为指导的经验教训)。Jodatime在这一点由java.time API过时。
你有一个特别好的理由继续使用它?如果没有,你应该移到java.time
API代替; 所以它不应该涉及很多工作要做所以这是非常相似的。
在jodatime,呼叫DateTimeFormat.forPattern("yyyy-MM-dd HH:mm")
。见的乔达时间的Javadoc。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句