Solved

validate time

Posted on 2004-10-07
6
871 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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

759 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

18 Experts available now in Live!

Get 1:1 Help Now