is Time String by Regex - Java java.util.regex

Java examples for java.util.regex:Match Date Time

Description

is Time String by Regex

Demo Code


//package com.java2s;

import java.util.regex.Pattern;

public class Main {
    private static Pattern PATTERN_TIME = Pattern
            .compile("((0?[0-9])|([1-2][0-3]))\\:([0-5]?[0-9])(\\:([0-5]?[0-9]))");

    public static boolean isTime(String time) {
        if (time == null)
            return false;
        else/*from  ww  w  . j a va2 s.c  o  m*/
            return PATTERN_TIME.matcher(time).matches();
    }
}

Related Tutorials