//获取当前时间Date date =DateUtil.date();Date date1 =DateUtil.date(Calendar.getInstance());Date date2 =DateUtil.date(System.currentTimeMillis());System.out.println(date+"\n"+date1+"\n"+date2);
String d ="2022-10-10";System.out.println(DateUtil.parse(d));//字符串转日期 2022-10-10 00:00:00System.out.println(DateUtil.format(DateUtil.parse(d),"yyyy-MM-dd"));//自定义日期格式化 2022-10-10System.out.println(DateUtil.year(DateUtil.parse(d)));//获取日期年份 2022System.out.println(DateUtil.month(DateUtil.parse(d)));//获取日期月份 9 从0开始计数
//日期时间偏移Date date =DateUtil.date();System.out.println(DateUtil.offsetDay(date,3));//加三天System.out.println(DateUtil.offsetDay(date,-3));//减三天System.out.println(DateUtil.offsetHour(date,3));//加三小时System.out.println(DateUtil.offsetHour(date,-3));//减三小时
Convert相关常用
int i =10;System.out.println(Convert.toStr(i));//int转StringString[] s ={"1","2","3","4"};System.out.println(Arrays.toString(Convert.toIntArray(s)));//String数组转换为int数组[1, 2, 3, 4]String[] split =Convert.toStr("2022_2").split("_");System.out.println(split[0]+"年-第"+split[1]+"季度");//Convert字符串分割拼接