Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Help me!

Posted on 1998-11-22
1
Medium Priority
?
170 Views
Last Modified: 2010-03-30
I need to compare two values: finish time and start time which gotten from text fields in my program.  I tried to use codes:
1).  if (txtfinishTime.getText() <= txtstartTime.getText())
            return true
      elase
           return false;

 
2).  SimpleDateFormat formatter = new SimpleDateFormat("hh:mm:ss");
  long ET = formatter.parse(txtfinishTime.getText()).getTime();
  long ST = formatter.parse(txtstartTime.getText()).getTime();
 if(ET <= ST)
     return true;
 else
   return false;

Both 1) and 2) are wrong. For 2). If I enter any time from 12:00:00 to 12:59:59 in the text field txtfinishTime, 9:00:00 in the text field txtstartTime, it returns true. But if I enter any time not from 12:00:00 to 12:59:59 and later than the txtstartTime 9:00:00, such as 9:30:00, it returns false.
Can anybody help me solve this problem? Thanks!!!!
0
Comment
Question by:leeann
[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
1 Comment
 
LVL 8

Accepted Solution

by:
Christoffer Swanström earned 240 total points
ID: 1228027
Your second approach should work with the following modification. Change the line:

SimpleDateFormat formatter = new SimpleDateFormat("hh:mm:ss");

to:

SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss");

The difference is that hh uses am/pm notation (hours from 1 to 12) and HH uses 24-hour notation (0 to 23). hh should also work, but for some reason it does not. You can verify this by printing out the values assigned to ET and ST: when the finish time is between 12:00:00 and 12:59:59 ET is negative, which just doesn't make sense (Date.getTime() returns the number of milliseconds elapsed since January 1st, 1970)

0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
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…
The viewer will learn how to implement Singleton Design Pattern in Java.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

610 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