validate time

how can i validate a time? say if i have 10:00 (hh:mm) the time is valid, if it is 25:10, it should be invalid.
Should be easier but its urgent.
LVL 32
Who is Participating?
zzynxConnect With a Mentor Software engineerCommented:
       SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");
        String s = "25:10";
        Date d = null;
        try {
            d = sdf.parse(s);
        } catch (ParseException ex) {
            System.out.println("Invalid Date");
zzynxSoftware engineerCommented:
Yeah parse it throught the date format classes and see if it throws an exception. If it throws an exception you know that there is a problem. Also if you do that you can even specify stuff like 12 hour times in stead of 24 hour and stuff like that.
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

ldbkuttyAuthor Commented:
I thought there might be SimpleTimeFormat!!!! he...hee..thats Ok. HH:mm & hh:mm - whats the difference.
zzynxSoftware engineerCommented:

H : Hour in day (0-23)
h : Hour in am/pm (1-12)
There is also a flag for 1-24 and 0-23 where the latter is the standard depending on your locale settings
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.