当前位置: 首页 > news >正文

企业项目中字符串工具类

        此工具类暂时包含如下功能:

  • isEmpty()判断字符串是否为空
  • subSpecifiedString()判断字符串是否超出指定长度,超出则截取到指定长度
  • yearMonthToDate()将年月的字符串转成年月日格式
  •  yearMonthToDateTime()将年月的字符串转成年月日时分秒格式
package com.zkdj.applet.common;import lombok.extern.slf4j.Slf4j;import java.util.regex.Pattern;/*** 类描述 -> 自定义字符串工具类** @Author: ywz* @Date: 2024/09/16*/
@Slf4j
public class StringUtils {/*** 方法描述 -> 判断字符串是否为空** @param str 字符串* @Author: ywz* @Date: 2024/09/16*/public static boolean isEmpty(String str) {return str == null || str.isEmpty();}/*** 方法描述 -> 判断字符串是否超出指定长度,超出则截取到指定长度** @param str    字符串* @param length 指定长度* @Author: ywz* @Date: 2024/09/16*/public static String subSpecifiedString(String str, int length) {return str.length() > length ? str.substring(0, length) : str;}/*** 方法描述 -> 将年月的字符串转成年月日格式** @param yearMonth 年月* @Author: ywz* @Date: 2024/09/16*/public static String yearMonthToDate(String yearMonth) {Pattern pattern = Pattern.compile("^[0-9]{4}-(0[1-9]|1[0-2])$");if (!pattern.matcher(yearMonth).matches()) {log.error("日期格式错误");return null;}return yearMonth + "-01";}/*** 方法描述 -> 将年月的字符串转成年月日时分秒格式** @param yearMonth 年月* @Author: ywz* @Date: 2024/09/16*/public static String yearMonthToDateTime(String yearMonth) {Pattern pattern = Pattern.compile("^[0-9]{4}-(0[1-9]|1[0-2])$");if (!pattern.matcher(yearMonth).matches()) {log.error("日期格式错误");return null;}return yearMonth + "-01 00:00:00";}
}
http://www.lryc.cn/news/439872.html

相关文章:

  • 下载github patch到本地
  • C++基础部分代码
  • neo4j(spring) 使用示例
  • 链接升级:Element UI <el-link> 的应用
  • 简单题26 - 删除有序数组中的重复项(Java)20240917
  • DFS:深搜+回溯+剪枝实战解决OJ问题
  • 命令语境中的“可以”的字词含义分析
  • 直播相关03-录制麦克风声音, ffmpeg 命名,使用命令行完成录音
  • VUE3中ref与reactive
  • 高职院校人工智能技术和无人机技术实训室建设方案
  • x-cmd pkg | shtris: 在终端体验经典的俄罗斯方块游戏
  • Linux基础---07文件传输及解决yum安装失效的方法
  • [项目][WebServer][Makefile Shell]详细讲解
  • ElementUI大坑Notification修改样式
  • vivado中的diagram
  • 项目实现:云备份②(文件操作、Json等工具类的实现)
  • ‌内网穿透技术‌总结
  • Git使用—把当前仓库的一个分支push到另一个仓库的指定分支、基于当前仓库创建另一个仓库的分支并推送到对应仓库(mit6828)
  • windows11+ubuntu20.04.6双系统安装
  • 如何通过 PhantomJS 模拟用户行为抓取动态网页内容
  • ARM驱动学习之8 动态申请字符类设备号
  • TCP.IP四层模型
  • 极狐GitLab DevSecOps 功能合集(七大安全功能)
  • 进阶SpringBoot之异步任务、邮件任务和定时执行任务
  • 【设计模式-桥接】
  • JVM JMM 专题篇 ( 12000 字详解 )
  • 【C++】—— list 模拟实现
  • Redis主要问题
  • vue3 ref的用法及click事件的说明
  • 通信工程学习:什么是HFC混合光纤同轴电缆