Fastjson时间类型转化问题

Date类型会转为时间戳,那么LocalDateTime类型怎么转为时间戳呢

public class RespData {
    private Date date;
    private LocalDateTime localDateTime;
    public RespData(Date date, LocalDateTime localDateTime) {
        super();
        this.date = date;
        this.localDateTime = localDateTime;
    }
    public Date getDate() {
        return date;
    }
    public void setDate(Date date) {
        this.date = date;
    }
    public LocalDateTime getLocalDateTime() {
        return localDateTime;
    }
    public void setLocalDateTime(LocalDateTime localDateTime) {
        this.localDateTime = localDateTime;
    }
    
}
    public static void main(String[] args) {
        RespData respData = new RespData(new Date(), LocalDateTime.now());
        System.out.println(JSON.toJSONString(respData));
        //{"date":1508989350039,"localDateTime":"2017-10-26T11:42:30.212"}
    }
阅读 9.2k
2 个回答

respData.toInstant(ZoneOffset.of("+8")).toEpochMilli();

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题