LocalDate of = LocalDate.of(2020, 8, 20);
LocalDate of1 = LocalDate.of(2020, 11, 2);
Period until = of.until(of1);//计算差几月零几天
long until = of.until(of1, ChronoUnit.MONTHS);//计算差多少年、月、天。
//Date 转LocalDate
LocalDate start = LocalDateTime.ofInstant(new Date().toInstant(), ZoneId.systemDefault()).toLocalDate();
//LocalDate 转Date
Date date = Date.from( of.atTime(0,0).atZone( ZoneId.systemDefault()).toInstant());
//long转LocalDateTime
long start;
LocalDateTime st = LocalDateTime.ofInstant(Instant.ofEpochMilli(start), ZoneId.systemDefault());
//字符串转LocalDatetime
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
LocalDateTime begin = LocalDateTime.parse("2018-08-09 15:18:20", dateTimeFormatter);
//大小比较
of.isBefore(of1);
实体转jsonArray
com.alibaba.fastjson.JSONArray jsonArray = com.alibaba.fastjson.JSONObject.parseArray(com.alibaba.fastjson.JSONObject.toJSONString(incomeParticularsDTOS));
jsonArray转实体
List<RouteDefinition> routeDefinitions = JSON.parseArray(configInfo, RouteDefinition.class);
实体转json再转map
Map<String, Object> voJson = com.alibaba.fastjson.JSONObject.parseObject(JSON.toJSONString(vo), new TypeReference<Map<String, Object>>() {});
字符串转json
JSONObject rentFreeJson = JSON.parseObject(this.rentFree);
java fastJson的使用,Date和LocalDate的转换
最新推荐文章于 2024-05-14 10:47:38 发布