java校验时间格式 HH:MM
- package com;
- import java.text.SimpleDateFormat;
- import java.util.Date;
- /**
- * @author Gerrard
- */
- public class CheckTimeHHMM {
- public static void main(String[] args) {
- boolean flg = checkTime("8:00");
- boolean flg3 = checkTime("24:00");
- boolean flg1 = checkTime("8:60");
- boolean flg2 = checkTime("25:00");
- boolean flg4 = checkTime("25:0-");
- boolean flg6 = checkTime("ss:0-");
- if (flg) {
- System.out.println("8:00是正确格式");
- }
- if (flg3) {
- System.out.println("24:00是正确格式");
- }
- if (!flg1) {
- System.out.println("8:60不是正确格式");
- }
- if (!flg2) {
- System.out.println("25:00不是正确格式");
- }
- if (!flg4) {
- System.out.println("25:0-不是正确格式");
- }
- if (!flg6) {
- System.out.println("ss:0-不是正确格式");
- }
- }
- /**
- * 校验时间格式(仅格式)
- */
- public static boolean checkHHMM(String time) {
- SimpleDateFormat dateFormat = new SimpleDateFormat("hh:mm");
- try {
- @SuppressWarnings("unused")
- Date t = dateFormat.parse(time);
- }
- catch (Exception ex) {
- return false;
- }
- return true;
- }
- /**
- * 校验时间格式HH:MM(精确)
- */
- public static boolean checkTime(String time) {
- if (checkHHMM(time)) {
- String[] temp = time.split(":");
- if ((temp[0].length() == 2 || temp[0].length() == 1) && temp[1].length() == 2) {
- int h,m;
- try {
- h = Integer.parseInt(temp[0]);
- m = Integer.parseInt(temp[1]);
- } catch (NumberFormatException e) {
- return false;
- }
- if (h >= 0 && h <= 24 && m <= 60 && m >= 0) {
- return true;
- }
- }
- }
- return false;
- }
- }
java校验时间格式 HH:MM的更多相关文章
- Excel将秒转换成标准的时间格式HH:MM:SS
Excel将秒转换成标准的时间格式HH:MM:SS 比如120秒,转换成00:02:00 Excel公式为: =TEXT(A1/86400,"[hh]:mm:ss") A1为秒数据 ...
- jQuery中校验时间格式的正则表达式小结
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/ ...
- JAVA中日期 yyyy-MM-dd HH:mm:ss和yyyy-MM-dd hh:mm:ss的区别
JAVA中日期 yyyy-MM-dd HH:mm:ss和yyyy-MM-dd hh:mm:ss的区别 : HH:24小时制 hh:12小时制 package time; import java.tex ...
- java时间"yyyy-mm-dd HH:mm:ss"转成Date
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String time="1 ...
- java获取时间格式
文章来源:https://www.cnblogs.com/hello-tl/p/9263602.html package com.util; import java.text.SimpleDateFo ...
- Java中时间格式处理,指定N天/小时等之后的时间
1)根据当前时间,获取具体的时刻的时间 N天前 M小时之前 可用 new Date().getTime() - 24 * 60 * 60 * 1000*N[N天之前]的方法来获取处理时间之后的具体的值 ...
- java格式化时间格式
System.out.println("Hello World!"); SimpleDateFormat format = new SimpleDateFormat( " ...
- js获取当前日期时间“yyyy-MM-dd HH:MM:SS”
获取当前的日期时间 格式“yyyy-MM-dd HH:MM:SS” 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 function getNowFormatDat ...
- [原]时间格式化hh:mm:ss和HH:mm:ss区别
hh:mm:ss 按照12小时制的格式进行字符串格式化 如果时间处于00:00:00——12:59:59,则返回的字符串正常 如果时间处于13:00:00——23:59:59,则返回的字符串是实际 ...
随机推荐
- JavaScript数独求解器
<html> <head> <style type="text/css"> .txt { width: 50; height: 50; back ...
- PHP-- 三种数据库随机查询语句写法
1. Oracle,随机查询查询语句-20条 select * from ( select * from 表名 order by dbms_random.value ) where rownum ...
- Keepalived+Redis高可用部署
1 Redis简介及安装 Redis是一个开源,先进的key-value存储,并用于构建高性能,可扩展的Web应用程序的完美解决方案. Redis从它的许多竞争继承来的三个主要特点: Redis数 ...
- mvc4 ajax.beginform表单验证
@{ Layout = null; } @model MvcApplication1.Models.User @using (Ajax.BeginForm("create", &q ...
- 安装Win7提示Windows无法安装到磁盘怎么办
Windows之家(www.windowszj.com):在安装Win7系统的过程中,由于每台电脑的状态不一样,比如硬件配置原因,或者是硬盘格式.硬盘状态等问题,会使得每台电脑在安装过程中都会有些不一 ...
- ubuntu下lamp配置
apache 在Ubuntu Linux上用 apt-get install apache2 安装Apache2后,竟然发现没有httpd.conf(位于/etc/apache2目录) Ubuntu的 ...
- 用 phylomatic 软件生成的进化树
用 phylomatic 软件生成的进化树 Phylomatic是在线软件,可以利用植物名录,按照APGIII的被子植物科的拓扑结构,生成进化树. 参考 张金龙博士 工作目录 setwd(" ...
- 当findById(Integer id)变成String类型
1.原Action // 添加跳转 @RequiresPermissions("pdaManager:v_add") @RequestMapping("/pdaManag ...
- 1.值得推荐的C/C++框架和库 (转)
值得学习的C语言开源项目 - 1. Webbench Webbench是一个在linux下使用的非常简单的网站压测工具.它使用fork()模拟多个客户端同时访问我们设定的URL,测试网站在压力下工作的 ...
- 【BZOJ-4591】超能粒子炮·改 数论 + 组合数 + Lucas定理
4591: [Shoi2015]超能粒子炮·改 Time Limit: 10 Sec Memory Limit: 256 MBSubmit: 95 Solved: 33[Submit][Statu ...