Solved

validate time

Posted on 2004-10-07
6
879 Views
Last Modified: 2008-02-01
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.
0
Comment
Question by:ldbkutty
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 37

Expert Comment

by:zzynx
ID: 12246930
SimpleDateFormat.parse()
0
 
LVL 37

Accepted Solution

by:
zzynx earned 250 total points
ID: 12246953
       SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");
        sdf.setLenient(false);
        String s = "25:10";
        Date d = null;
        try {
            d = sdf.parse(s);
        } catch (ParseException ex) {
            System.out.println("Invalid Date");
        }
0
 
LVL 3

Expert Comment

by:RuadRauFlessa
ID: 12246959
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.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 32

Author Comment

by:ldbkutty
ID: 12246963
I thought there might be SimpleTimeFormat!!!! he...hee..thats Ok. HH:mm & hh:mm - whats the difference.
0
 
LVL 37

Expert Comment

by:zzynx
ID: 12246978
Thanks

H : Hour in day (0-23)
h : Hour in am/pm (1-12)
0
 
LVL 3

Expert Comment

by:RuadRauFlessa
ID: 12246998
There is also a flag for 1-24 and 0-23 where the latter is the standard depending on your locale settings
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question