Note that there are some explanatory texts on larger screens.

plurals
  1. POJava: Getting time interval
    primarykey
    data
    text
    <p>I am on a project to capture the interval time in hh:mm. I have 2 buttons named btnTimeOut &amp; btnTimeIn both capturing the system time when clicked. The requirement is to get the interval between the btnTimeOut &amp; btnTime in hh:mm, etc. 12:30 - 10:00 = 02:30 (hh:mm).</p> <p>Currently I used the following codes for the interval but it returns as minutes, etc. 12:30 - 10:00 = 150 minutes.</p> <pre><code> String timeOut = lblTimeOut.getText(); String timeIn = lblTimeIn2.getText(); SimpleDateFormat format = new SimpleDateFormat("hh:mm"); Date d1 = null; Date d2 = null; try { d1 = format.parse(timeOut); d2 = format.parse(timeIn); } catch (Exception e){ e.printStackTrace(); } long diff = d2.getTime() - d1.getTime(); long diffMinutes = diff / (60 * 1000); long diffHours = diff / (60 * 60 * 1000); lblSurface.setText(String.valueOf(diffMinutes)); </code></pre> <p>How to get the duration in the form <code>hh:mm</code>?</p> <p>I used Joda time and return with Invalid format: "12:19" is malformed at ":19". As for my other buttons which trigger the display time.</p> <pre><code>DateFormat timeFormat = new SimpleDateFormat("hh:mm"); Date date = new Date(); String time = timeFormat.format(date); lblTimeIn2.setText(time); Timer timer = new Timer(1000, timerListener); // to make sure it doesn't wait one second at the start timer.setInitialDelay(0); timer.start(); } </code></pre> <p>I've no idea what is wrong, do I need to use joda time for displaying time for my other label too?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload