| | |
| | | import java.lang.reflect.Type; |
| | | import java.text.ParseException; |
| | | import java.text.SimpleDateFormat; |
| | | import java.time.Duration; |
| | | import java.time.LocalDateTime; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.Calendar; |
| | | import java.util.Date; |
| | | import java.util.Locale; |
| | |
| | | return lang; |
| | | } |
| | | |
| | | //获取当前系统的语言环境 |
| | | public static String getLang4Socket(HttpSession httpSession) { |
| | | Locale locale = Locale.getDefault();//对Locale类实例化定义 |
| | | String lang = locale.getLanguage(); |
| | | //String lang = "zh"; |
| | | String str = (String) httpSession.getAttribute("lang"); |
| | | if (str != null) { |
| | | lang = str; |
| | | } |
| | | return lang; |
| | | } |
| | | |
| | | /** |
| | | * 输入验证:路径遍历,防止恶意符号影响文件体系 |
| | | * 过滤掉特殊字符 ”/\" : | * ? < >” |
| | |
| | | * 过滤掉特殊字符 ”/\" : | * ? < >” |
| | | */ |
| | | public static boolean filterPwd(String pwd){ |
| | | String regex="^(?=.*[a-z])(?=.*[A-Z])(?=.*\\d)(?=.*[!@#$%^&*()_+])[a-zA-Z\\d!@#$%^&*()_+]{8,}$"; |
| | | String regex="^(?=.*[a-z])(?=.*[A-Z])(?=.*\\d)(?=.*[!@#$%^&*()_+\\-])[a-zA-Z\\d!@#$%^&*()_+\\-]{8,}$"; |
| | | Pattern pattern = Pattern.compile(regex); |
| | | Matcher matcher = pattern.matcher(pwd); |
| | | return matcher.matches(); |
| | | } |
| | | |
| | | /** |
| | | * 将时间字符串(格式HH:mm:ss)转换为秒数 |
| | | * |
| | | * @param timeStr 时间字符串 |
| | | * @return 转换后的秒数 |
| | | */ |
| | | public static int convertToSeconds(String timeStr) { |
| | | // 使用冒号(:)分割时间字符串 |
| | | String[] parts = timeStr.split(":"); |
| | | |
| | | // 验证时间字符串是否有效(假设总是包含三个部分) |
| | | if (parts.length != 3) { |
| | | throw new IllegalArgumentException("时间字符串格式不正确,应为HH:mm:ss"); |
| | | } |
| | | |
| | | // 解析小时、分钟和秒 |
| | | int hours = Integer.parseInt(parts[0]); |
| | | int minutes = Integer.parseInt(parts[1]); |
| | | int seconds = Integer.parseInt(parts[2]); |
| | | |
| | | // 转换为总秒数 |
| | | // 注意:1小时 = 3600秒,1分钟 = 60秒 |
| | | int totalSeconds = hours * 3600 + minutes * 60 + seconds; |
| | | |
| | | return totalSeconds; |
| | | } |
| | | |
| | | public static String parseDurationDirectly(String timeStr) { |
| | | // 获取当前时间 |
| | | LocalDateTime now = LocalDateTime.now(); |
| | | String[] parts = timeStr.split(":"); |
| | | if (parts.length != 3) { |
| | | throw new IllegalArgumentException("时间长度字符串格式不正确"); |
| | | } |
| | | int hours = Integer.parseInt(parts[0]); |
| | | int minutes = Integer.parseInt(parts[1]); |
| | | int seconds = Integer.parseInt(parts[2]); |
| | | Duration timeToAdd = Duration.ofHours(hours).plusMinutes(minutes).plusSeconds(seconds); |
| | | // 将时间长度加到当前时间上 |
| | | LocalDateTime updatedTime = now.plus(timeToAdd); |
| | | return updatedTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")); |
| | | } |
| | | public static void main(String[] args) { |
| | | System.out.println(filterPwd("Aa@123456")); |
| | | //System.out.println(filterPwd("Aa@123456")); |
| | | |
| | | // 时间长度字符串 |
| | | String timeToAddStr = "00:00:34"; |
| | | String time =parseDurationDirectly(timeToAddStr); |
| | | System.out.println(time); |
| | | } |
| | | |
| | | } |