java.util.Date date = new java.util.Date();
String s = date.toString();
System.out.println(date);
System.out.println(s);
System.out.println(“Date——>Long :”+date.getTime());
System.out.println(“Date——>Instant :”+date.toInstant());
System.out.println(“LocalDateTime:”+LocalDateTime.now());
Timestamp timestamp = Timestamp.valueOf(LocalDateTime.now());
System.out.println("LocalDateTime——>Long :"+timestamp.getTime());
LocalDateTime localDateTime = LocalDateTime.ofInstant(date.toInstant(), ZoneId.systemDefault());
System.out.println("加2天:"+ localDateTime.plusDays(2));
System.out.println("减2小时:"+ localDateTime.plusHours(-2));
System.out.println("减2天:"+ localDateTime.plusDays(-2));
System.out.println("差的日期:"+ localDateTime.compareTo(localDateTime.plusDays(2)));
BigDecimal bigDecimal1 = new BigDecimal("3321");
BigDecimal bigDecimal2 = new BigDecimal("4423");
//四舍五入
BigDecimal divide = bigDecimal2.divide(bigDecimal1,2,BigDecimal.ROUND_HALF_UP);
System.out.println("保留两位小数:"+divide);
输出结果:
Wed Dec 04 16:13:14 CST 2019
Wed Dec 04 16:13:14 CST 2019
Date——>Long :1575447194133
Date——>Instant :2019-12-04T08:13:14.133Z
LocalDateTime:2019-12-04T16:13:14.460
LocalDateTime——>Long :1575447194460
加2天:2019-12-06T16:13:14.133
减2小时:2019-12-04T14:13:14.133
减2天:2019-12-02T16:13:14.133
差的日期:-2
保留两位小数:1.33