Results 1 to 5 of 5
  1. #1
    gorgon777 is offline Member
    Join Date
    Jan 2014
    Posts
    15
    Rep Power
    0

    Exclamation How to reduce time in Java?

    Hi guys, wondering if you can help.

    I have two string representations of time in "HH:MM:SS" and I want to minus one time from the other.

    For example if a = 10:20:30 and b = 00:50:20, i would get 09:30:10. What is the best way to do this?

    Kind Regards
    Mark

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,411
    Rep Power
    25

    Default Re: How to reduce time in Java?

    One way: extract the hr and min and sec for each and do the math with borrows as needed.
    Another way could be to parse the Strings using DateFormat and then use some method(s) in the Calendar class.
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    makpandian's Avatar
    makpandian is offline Senior Member
    Join Date
    Dec 2008
    Location
    Chennai
    Posts
    448
    Rep Power
    6

    Default Re: How to reduce time in Java?

    One way: extract the hr and min and sec for each and do the math with borrows as needed.
    Another way could be to parse the Strings using DateFormat and then use some method(s) in the Calendar class.
    Second way is the best according to me.
    Mak
    (Living @ Virtual World)

  4. #4
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,016
    Rep Power
    6

    Default Re: How to reduce time in Java?

    For dates I agree. For time, I can go either way. Its an easy to split format, so its maybe three lines of very basic code to do the math.

    What I can't judge is what the BEST WAY is to do it, I'm not the king of all developers. I'd rather look for a way that works.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  5. #5
    makpandian's Avatar
    makpandian is offline Senior Member
    Join Date
    Dec 2008
    Location
    Chennai
    Posts
    448
    Rep Power
    6

    Default Re: How to reduce time in Java?

    @gimbal2

    To indentify the best approach we do need to be neither a king nor a prince. It's up to those who are gonna use it.
    Mak
    (Living @ Virtual World)

Similar Threads

  1. How to reduce memory consumption in Java Desktop?
    By fanjavaid in forum Advanced Java
    Replies: 16
    Last Post: 07-19-2013, 04:59 AM
  2. How to reduce fractions in Java?
    By uselessparadigm in forum New To Java
    Replies: 9
    Last Post: 04-09-2012, 08:02 PM
  3. how to reduce the thread processing time
    By chnaveen in forum Threads and Synchronization
    Replies: 3
    Last Post: 07-16-2011, 09:15 AM
  4. How do I reduce lag in a java game that I am making?
    By rajkobie in forum New To Java
    Replies: 4
    Last Post: 05-13-2011, 03:24 PM
  5. how to reduce the thread sleep time and wake up the thread
    By baktha.thalapathy in forum Threads and Synchronization
    Replies: 2
    Last Post: 06-24-2010, 07:36 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •