一、时间
1.1、当天时间
2023-04-28 10:03:43
DateTime date = DateUtil.date();2023-04-28 10:09:19
String now = DateUtil.now();2023-04-28 10:12:06
Date date2 = DateUtil.parse(now, "yyyy-MM-dd HH:mm:ss");2023-04-28
String today = DateUtil.today();
DateTime转成String
2023-04-28
String formatDate = DateUtil.formatDate(date);
2023-04-28 10:14:38
String formatDateTime = DateUtil.formatDateTime(date);
1.2 、其它时间
昨天:2023-04-27 10:05:19
DateTime yesterday = DateUtil.yesterday();明天:2023-04-29 10:05:19
DateTime tomorrow = DateUtil.tomorrow();上个月当前时间
DateTime lastMonth = DateUtil.offsetMonth(DateUtil.parse(DateUtil.now(), "yyyy-MM-dd HH:mm:ss");, -1);
上个月开始时间
Date startTimeMonth = DateUtil.beginOfMonth(lastMonth);
上个月最后一天
DateTime endTimeMonth = DateUtil.endOfMonth(lastMonth);
1.3 常见的时间偏移量
三天后:2023-05-01 10:18:14
DateTime newDate2 = DateUtil.offsetDay(date, 3);
三小时前:2023-04-28 07:17:23
DateTime newDate3 = DateUtil.offsetHour(date, -3);
二、集合和字符串
新建集合
List<String> colList = CollUtil.newArrayList("a","b","c","d","e");
List<String> colList2 = CollUtil.newArrayList("a","b","c","w");集合转成字符串:a#b#c#d#e
String str = CollUtil.join(colList, "#");
字符串转成集合:[a, b, c, d, e]
List<String> split = StrUtil.split(str, "#");
String str="[[1393],[1408]]"; //去掉[ 和 ] str = str.replaceAll("\\[|\\]", ""); List<String> split = StrUtil.split(str, ",");
计算集合的单差集,即只返回【集合1】中有,但是【集合2】中没有的元素:[d, e]
List<String> subtractList = CollUtil.subtractToList(colList, colList2);
判断是否为空
boolean notEmpty = CollUtil.isNotEmpty(colList);
System.out.println(notEmpty); ---------trues
hasEmpty只判断是否为null或者空字符串(""),hasBlank则会把不可见字符也算做空
String s1 = " ";
boolean strFlag1 = StrUtil.hasBlank(s1);
System.out.println(strFlag1); -----------true
strFlag2 = false
boolean strFlag2 = StrUtil.hasEmpty(s1);
System.out.println(strFlag2); -----------false
去掉后缀
String fileNameSuffix = StrUtil.removeSuffix("pretty_girl.jpg", ".jpg");
System.out.println(fileNameSuffix); -------------pretty_girl
去掉前缀
String fileNamePrefix = StrUtil.removePrefix("app.pretty_girl", "app.");
System.out.println(fileNamePrefix); ------------pretty_girl
三、读取配合文件
String artInfoMappingPath='config/es/art_info_index_mapping.json'
String artInfoMapping = ResourceUtil.readStr(artInfoMappingPath, StandardCharsets.UTF_8);
其中json文件放到resources中config/es目录下