package com.puhui.xiaojin.utils;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.logging.SimpleFormatter;
/**
* @author Created By Matteo
* @date 2020/12/5 18:11
* @Description: 时间格式化
*/
public class DateUtils {
/**
* HH:MM:SS
*/
public static boolean checkTimeHHMMSS(String time){
if (checkHHMMSS(time)){
String[] temp = time.split(":");
if (temp[0].length()==2||temp[0].length()==1&&temp[1].length()==2&&temp[2].length()==2){
int h,m,s;
h = Integer.parseInt(temp[0]);
m = Integer.parseInt(temp[1]);
s = Integer.parseInt(temp[2]);
if (h>=0 && h<=24&& m<=60 && m>=0 && s>=0 && s<=60){
return true;
}
}
}
return false;
}
/**
* 校验时间格式(仅格式)
* @param time
* @return
*/
private static boolean checkHHMMSS(String time) {
SimpleDateFormat formatter = new SimpleDateFormat("hh:mm:ss");
try {
Date parse = formatter.parse(time);
} catch (ParseException e) {
return false;
}
return true;
}
}
仅时分秒类型验证及转换(HH:MM:SS)
最新推荐文章于 2024-06-13 10:02:14 发布