Solved

validate time

Posted on 2004-10-07
6
874 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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
eclipse formatting 6 87
windows explorer path to command prompt 5 42
Desingning Refactoring existing code 2 24
Which non-HTML GUI front end to use with Java? 3 19
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

816 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