Solved

validate time

Posted on 2004-10-07
6
872 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
  • 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Arrays.asList  VS  ArrayList 4 45
MySqlDump not dumping triggers 1 17
use lov values 2 33
Configure a Bean in an XML file 4 12
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
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…
This video teaches viewers about errors in exception handling.

895 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now