Math常用类
ceil 向上取整
double d = 3.5;
System.out.println(Math.round(d));
floor 向下取整
round 四舍五入
pow 求次方
double d = 3.5;
System.out.println(Math.pow(d, 2));
sqrt 求平方根
max/min 最大/最小值
random 生成随机数(假随机数)
//random 随机数属于随机数工具
double dd = Math.random();
//生成13到15的随机数
double target = (dd * 2) + 13 ;
System.out.println(target);
//生成一个0-10的随机数
Random random = new Random();
System.out.println(random.nextInt(11));
Date 时间工具类
简单的时间格式工具
//简单的时间格式工具
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
System.out.println(sdf.format(d));
转时间类型
String str = "2020-11-06 10:15:26";
Date d3 = sdf.parse(str);
getDate 拿到日期
getDay 拿到星期
System.out.println(d.getDay());
after 在…之后
before 在…之前
Date d1 = new Date(1);
Date d2 = new Date(2);
System.out.println(d1.before(d2));