1. package com;
  2. import java.text.SimpleDateFormat;
  3. import java.util.Date;
  4. /**
  5. * @author Gerrard
  6. */
  7. public class CheckTimeHHMM {
  8. public static void main(String[] args) {
  9. boolean flg = checkTime("8:00");
  10. boolean flg3 = checkTime("24:00");
  11. boolean flg1 = checkTime("8:60");
  12. boolean flg2 = checkTime("25:00");
  13. boolean flg4 = checkTime("25:0-");
  14. boolean flg6 = checkTime("ss:0-");
  15. if (flg) {
  16. System.out.println("8:00是正确格式");
  17. }
  18. if (flg3) {
  19. System.out.println("24:00是正确格式");
  20. }
  21. if (!flg1) {
  22. System.out.println("8:60不是正确格式");
  23. }
  24. if (!flg2) {
  25. System.out.println("25:00不是正确格式");
  26. }
  27. if (!flg4) {
  28. System.out.println("25:0-不是正确格式");
  29. }
  30. if (!flg6) {
  31. System.out.println("ss:0-不是正确格式");
  32. }
  33. }
  34. /**
  35. * 校验时间格式(仅格式)
  36. */
  37. public static boolean checkHHMM(String time) {
  38. SimpleDateFormat dateFormat = new SimpleDateFormat("hh:mm");
  39. try {
  40. @SuppressWarnings("unused")
  41. Date t = dateFormat.parse(time);
  42. }
  43. catch (Exception ex) {
  44. return false;
  45. }
  46. return true;
  47. }
  48. /**
  49. * 校验时间格式HH:MM(精确)
  50. */
  51. public static boolean checkTime(String time) {
  52. if (checkHHMM(time)) {
  53. String[] temp = time.split(":");
  54. if ((temp[0].length() == 2 || temp[0].length() == 1) && temp[1].length() == 2) {
  55. int h,m;
  56. try {
  57. h = Integer.parseInt(temp[0]);
  58. m = Integer.parseInt(temp[1]);
  59. } catch (NumberFormatException e) {
  60. return false;
  61. }
  62. if (h >= 0 && h <= 24 && m <= 60 && m >= 0) {
  63. return true;
  64. }
  65. }
  66. }
  67. return false;
  68. }
  69. }

java校验时间格式 HH:MM的更多相关文章

  1. Excel将秒转换成标准的时间格式HH:MM:SS

    Excel将秒转换成标准的时间格式HH:MM:SS 比如120秒,转换成00:02:00 Excel公式为: =TEXT(A1/86400,"[hh]:mm:ss") A1为秒数据 ...

  2. jQuery中校验时间格式的正则表达式小结

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/ ...

  3. 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 ...

  4. java时间"yyyy-mm-dd HH:mm:ss"转成Date

    SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String time="1 ...

  5. java获取时间格式

    文章来源:https://www.cnblogs.com/hello-tl/p/9263602.html package com.util; import java.text.SimpleDateFo ...

  6. Java中时间格式处理,指定N天/小时等之后的时间

    1)根据当前时间,获取具体的时刻的时间 N天前 M小时之前 可用 new Date().getTime() - 24 * 60 * 60 * 1000*N[N天之前]的方法来获取处理时间之后的具体的值 ...

  7. java格式化时间格式

    System.out.println("Hello World!"); SimpleDateFormat format = new SimpleDateFormat( " ...

  8. 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 ...

  9. [原]时间格式化hh:mm:ss和HH:mm:ss区别

    hh:mm:ss   按照12小时制的格式进行字符串格式化 如果时间处于00:00:00——12:59:59,则返回的字符串正常 如果时间处于13:00:00——23:59:59,则返回的字符串是实际 ...

随机推荐

  1. JavaScript数独求解器

    <html> <head> <style type="text/css"> .txt { width: 50; height: 50; back ...

  2. PHP-- 三种数据库随机查询语句写法

    1. Oracle,随机查询查询语句-20条 select * from (  select  *  from 表名 order by dbms_random.value ) where rownum ...

  3. Keepalived+Redis高可用部署

    1   Redis简介及安装 Redis是一个开源,先进的key-value存储,并用于构建高性能,可扩展的Web应用程序的完美解决方案. Redis从它的许多竞争继承来的三个主要特点: Redis数 ...

  4. mvc4 ajax.beginform表单验证

    @{ Layout = null; } @model MvcApplication1.Models.User @using (Ajax.BeginForm("create", &q ...

  5. 安装Win7提示Windows无法安装到磁盘怎么办

    Windows之家(www.windowszj.com):在安装Win7系统的过程中,由于每台电脑的状态不一样,比如硬件配置原因,或者是硬盘格式.硬盘状态等问题,会使得每台电脑在安装过程中都会有些不一 ...

  6. ubuntu下lamp配置

    apache 在Ubuntu Linux上用 apt-get install apache2 安装Apache2后,竟然发现没有httpd.conf(位于/etc/apache2目录) Ubuntu的 ...

  7. 用 phylomatic 软件生成的进化树

    用 phylomatic 软件生成的进化树 Phylomatic是在线软件,可以利用植物名录,按照APGIII的被子植物科的拓扑结构,生成进化树. 参考 张金龙博士 工作目录 setwd(" ...

  8. 当findById(Integer id)变成String类型

    1.原Action // 添加跳转 @RequiresPermissions("pdaManager:v_add") @RequestMapping("/pdaManag ...

  9. 1.值得推荐的C/C++框架和库 (转)

    值得学习的C语言开源项目 - 1. Webbench Webbench是一个在linux下使用的非常简单的网站压测工具.它使用fork()模拟多个客户端同时访问我们设定的URL,测试网站在压力下工作的 ...

  10. 【BZOJ-4591】超能粒子炮·改 数论 + 组合数 + Lucas定理

    4591: [Shoi2015]超能粒子炮·改 Time Limit: 10 Sec  Memory Limit: 256 MBSubmit: 95  Solved: 33[Submit][Statu ...