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,则返回的字符串是实际 ...
随机推荐
- POJ2155 Matrix二维线段树经典题
题目链接 二维树状数组 #include<iostream> #include<math.h> #include<algorithm> #include<st ...
- ssh配置文件ssh_config和sshd_config区别
问题描述:在一次配置ssh端口和秘钥登录过程中,修改几次都没有成功.最后发现修改的是ssh.config,原因是习惯tab一下,实在是眼拙! ssh_config和sshd_config配置文件区别: ...
- iOS不得姐项目--封装状态栏指示器(UIWindow实现)
一.头文件 #import <UIKit/UIKit.h> @interface ChaosStatusBarHUD : NSObject /** 显示成功信息 */ + (void)sh ...
- Django-Model 使用
添加 更改 删除 查找 /1 使用get 方式查找,只有一条数据,并如果数据不存在的时候会报错,建议不用 User.objects.get(uname=xxx) User. 模型 get(uname= ...
- js_RGB转16进制(rgb2hex)
输入:rgb(13,0,255) 输出:#0d00ff 在线颜色转换工具:http://www.atool.org/colorpicker.php 1 2 3 4 5 6 7 8 9 function ...
- 【POJ 2482】Stars in Your Window
http://poj.org/problem?id=2482 线段树扫描线 #include<cstdio> #include<cstring> #include<alg ...
- Web前端性能优化教程08:配置ETag
本文是Web前端性能优化系列文章中的第五篇,主要讲述内容:配置ETag.完整教程可查看:Web前端性能优化 什么是ETag? 实体标签(EntityTag)是唯一标识了一个组件的一个特定版本的字符串, ...
- [分类算法] :SVM支持向量机
Support vector machines 支持向量机,简称SVM 分类算法的目的是学会一个分类函数或者分类模型(分类器),能够把数据库中的数据项映射给定类别中的某一个,从而可以预测未知类别. S ...
- Leetcode 343. Integer Break
Given a positive integer n, break it into the sum of at least two positive integers and maximize the ...
- 【caffe】loss function、cost function和error
@tags: caffe 机器学习 在机器学习(暂时限定有监督学习)中,常见的算法大都可以划分为两个部分来理解它 一个是它的Hypothesis function,也就是你用一个函数f,来拟合任意一个 ...