How can I handle a time interval ?

I have an application in which the users will enter the time spent on specific activities. The time spent will be in hours and minutes(eg. 8.00, 2.30, 4.50 ). Which is the best approach in Java to represent this time interval and to perform basic operations like sum?
I have looked into the API but The classes I have found (Date, Time, Calendar) all refer to instant of time not to interval of time.
Thanks for your help.
Federico.

Parse the times into Date objects, (Using DateFormat.getTimeInstance etc.).
Date stores the time in milliseconds since 1970. So you just have to subtract.
final static DateFormat timeFormat = DateFormat.getTimeInstance();
Date startTime = timeFormat.parse(strStart);
Date endTime = timeFormat.parse(strEnd);
long gapMillis = endTime.getTime() - startTime.getTime();You may want to check that endtime is after starttime and, if not, add a day using Calendar.

Similar Messages

  • How can we handle browser settings while dealing with the security ?

    Hi ,
    how can we handle browser settings while dealing with the security ?When we configured security in web.xml , during the first request the container is asking for the authentication credentials once they are provided it go's on. but when the user gives a fresh request from the second window within the same browser that time it is not asking for authentication. How can we overcome this.Is there anything to do with server configurations?
    How can we make the container no to keep the things or act like session?

    Ya... I am taking a small example need not happen always but a kind of possibility i am thinking off.
    once the user sign out and just left without closing the browser and a friend (suppose not a good friend ... just kidding...) of that user may open the same jsp or file .This time the security is breached. If that feature or property exists....
    I know what you might say ... the user will log-out before leaving where a programer might invalidate the session at the time of log out.
    Consider the case of a bad Programing or just a programer might forget to invalidate,At that time as a application administrator how can he solve that issue.
    Thanks.......
    Edited by: user8483670 on Jun 6, 2011 1:08 AM
    Edited by: user8483670 on Jun 6, 2011 1:09 AM

  • How can I handle exception? - to give user more friendly notification

    Hi!
    User gets an error:
    'Error in mru internal routine: ORA-20001: Error in MRU: row= 1, ORA-20001: ORA-20001: Current version of data in database has changed since user initiated update process. current checksum =...'
    How can I handle this exception (when two users want to modify the same set of data at the same time)? I would like to hide the above error message and give user more friendly notification.
    Thanks in advance,
    Tom

    Thanks Vikas for your answer.
    These workarounds are really creative and I want to use one of them. BUT my problem is to 'catch' the exception/error when two users want to modify the same set of data at the same time.
    Those solutions which we can read about in this link you gave me describe handling exceptions in pl/sql processes. How can I catch the error I am talking about in pl/sql code?
    Code would be like this:
    DECLARE
    two_users EXCEPTION;
    BEGIN
    IF --catch the error
    THEN RAISE two_users;
    END IF;
    EXCEPTION WHEN two_users
    THEN :HIDDEN_ITEM := 'Error Message';
    END;
    What should I put in a place where there is '--catch the error' ??
    Thanks in advance,
    Tom

  • Errors in flat file records? how can i handle them?

    Hi All,
    I am new for BDC. I am uploading customer(XD01) records using BDC caltransaction method.my problem is when i am running the program, some times my program is not updating the records because of my flat file errors. after i correcting the error records and if i run the same program already updated records not processing. my program not running. what i need to do? how can i handle the flat file for reprocessing the error records?
    i have around 50,000 records in my flat file.

    your program accepts a flat file say the structure of it is structure_load and you create another structure similar to structure_load and name it structure_error.
    loop at itab_load.
    call transactions...
    if success..
    commit work and wait X sec.
    else.
    move-corresponding field to structure_error
    append structure_error.
    endif.
    endloop.
    write the file stru_error to PC or app server and make the changes  to the data and use the str_error as input to your code again..

  • How can i get current time in different TimeZone

    Hi alls,
    How can i get current time in different TimeZone.
    I've tried
    final Calendar calendar = Calendar.getInstance(GMT0_TIME_ZONE);
    final Date date = calendar.getTime();
    but it returns current time in my time zone not in GMT0

    a simple way would be:Sometimes gets you the right result (not during daylight saving), but always the wrong way.
    I would strongly recommend getting into the habit of handling Dates correctly. A Date is a universal instant in time - the number of milliseconds since midnight GMT on 1 January 1970. That instant corresponds to various dates and times, depending on your time zone and the effect of daylight saving. You make that conversion of a universal instant to a localized date/time using Calendar and DateFormat.

  • Mysql datetime datatype, from that datetime how can i compar only time part

    Hello i have database table in mysql, there is Datetime datatype column, from that datetime how can i compare only time part .....??
    Thanks in advance...

    Note you can't simply just compare time via equality however.
    Timestamp resolution is to the second or even milli-second. No user wants to match a time to an exact millisecond.
    What they want is something like a match by hour - for example returning the number of transactions that happened from 1pm to 2pm. Even that isn't completely correct because then you need to consider whether 1pm and/or 2pm is inclusive or exclusive. Normally one end will be inclusive and the other exclusive.
    So first you need to define what the period is.
    Then construct the range.
    Then pass the range and, as already mentioned, use specific functions to handle the extraction of the time.

  • How can I use my time capsule with windows7

    How can I use my time capsule with windows7?

    This is asked regularly.
    https://discussions.apple.com/message/10978060#10978060
    Look at the more like this. On the right column next to the post.
    Load airport utility for windows.. which will also load bonjour for windows.
    In windows explorer type \\TCname or \\TCipaddress (replacing with the actual values.. names with spaces will give you trouble so change all names in the TC to SMB compatible or actual ip address).

  • How can I copy a time machine backup from one Time Capsule to another ?

    How can I copy a time machine backup from one Time Capsule to another ? I bought a 1 Tb Time Capsule to replace my 512Mb Time Capsule. Now, I like to copy my time machine backup from the old Time Capsule to the new one so I can keep using my backup.

    from this support article: 
    (click on image to enlarge)

  • After a clean install, how can I continue using Time Machine?

    After a clean install, how can I continue using Time Machine?
    I booted from my recovery partition, erased my HD, installed the same OS, (Lion, 10.7.5) then restored from my TM.
    If it asks if i want to use TM, I say yes. When I chose the drive, it seems to want to start all over, instead of just picking up where I left off.
    Is there any way of picking up where I left off?

    Hi Frank,
    You are sure you looking in your Library in /Users/YOUR_USERNAME/Library and not /Library at the top level of your harddrive?
    When you open iCal what do you see?  Are the calendars the two default Home and Work ones?
    I really appreciate the responses -- especially if you are in the UK as opposed to Ontario.
    Why, do you have something against London Ontario?
    John M

  • Hi! how can I set the time machine/capsule back-up intervals? Heron 2

    HI! EVERYBODY,
    HOW CAN I SYNC 2 TIME CAPSULES INSTALLED IN TWO DIFFERENT LOCATIONS, MAIN HOME AND SUMMER HOME?
    THANK YOU FOR YOUR HELP.
    MERCi
    HERON2

    To use different backup intervals use TimeMachineEditor 2.5.3. I do not think syncing two Time Capsule to one another is feasible or possible. For all things Time Machine visit Pondini's Time Machine FAQ

  • I have just installed a 2TB time capsule on my iMac i7, it see my second 1TB hard drive but the 256 SSD doesn't come up in the list of hard drives I can back up. How can I enable the time machine to see my first SSD 256gb hard drive?

    I have just installed a 2TB time capsule on my iMac i7, it see my second 1TB hard drive but the 256 SSD doesn't come up in the list of hard drives I can back up. How can I enable the time machine to see my first SSD 256gb hard drive?

    iLife is preinstalled on all the Macs. If you purchased iLife in the App Store or your computer came without DVDs, open App Store > Purchases and download the applications. If your Mac came with discs, insert the Applications DVD and install iLife applications

  • My wife and I share an apple id how can we use face time

    My wife and I share an apple ID. How can we use face time?

    Try the MacBook Pro forums and perhaps Apple ID or Facetime, this forum does not deal with notebooks or facetime.
    MacBook Pro
    https://discussions.apple.com/community/notebooks/macbook_pro 
    https://discussions.apple.com/community/mac_os?view=discussions
    http://www.apple.com/support/macbookpro
    http://www.apple.com/support/

  • How can I fix a time error on my MacBook?

    How can I fix a time error on my MacBook?

    If, after checking the settings in Sys Pref> Date/Time nothing really changes
    you could see if a reset of the NVRAM could help.
    Read carefully & when using the keyboard sequence, let the computer
    start tone sound three times, to be sure the reset has really occurred.
    •About NVRAM & PRAM:
    http://support.apple.com/kb/HT1379
    Does the time gain by itself? Is the Time Server set to automatically
    keep the computer time corrected when you are online? You may
    also try the manual settings, if the computer had not been used in
    some time, because if the battery gets too low, the capacitor in a
    portable computer can also lose power, & NVRAM - PRAM chip
    settings could be lost. However by then, Date can also be wrong.
    Was there anything else going on that may have affected this?
    Sometimes odd items are related to something else.
    Good luck & happy computing!

  • How can I set my time capsule to back-up only once a day?

    How can I set my time capsule to only back-up once a day.  It appears to be backing up several times a day.  Not sure there is a set schedule for the back-ups and they take a great deal of time; over an hour each.

    tdenny2 wrote:
    Not sure there is a set schedule for the back-ups and they take a great deal of time; over an hour each.
    Then something is wrong.  Changing the schedule will only deal with the symptom (and give up one of the better features of Time Machine's usually quick and unobtrusive hourly backups).
    See if the size of the backups makes sense, considering what you've changed since the previous one.  If it seems much too large, that may be the problem.  See #D4 in Time Machine - Troubleshooting for some common culprits and ways to see just what's going on.
    If the sizes seem reasonable, see #D2 in the same link for things that can cause extra-slow backups.

  • For iPhone4 with iOS7, how can i see the time of day for a voice memo instead of the length of time for the recording?

    For iPhone 4S with iOS7 version 7.0.2, how can I see the time of day for a voice memo, as opposed to its length (of time)?

    For iPhone 4S with iOS7 version 7.0.2, how can I see the time of day for a voice memo, as opposed to its length (of time)?

Maybe you are looking for

  • How To Show a Tab/Page in APEX for specific users

    Hi, I have created a page in APEX. I want to restrict the page access to all the users except two or 3 users(Admin users ).How do i restrict the access for a page/tab.Please help.I have enabled SSO authentication for my Application.

  • Create new article:  BAPI_MATERIAL_MAINTAINDATA_RT

    Hi all, When i try to create a new article by using BAPI_MATERIAL_MAINTAINDATA_RT i am getting the follow success message M3801 ("Material & changed") but article is not created. After sending the BAPI_MATERIAL_MAINTAINDATA_RT and returning without a

  • Authorization checks

    Hi all My requirement is As we have 7 company and particular user are authorized for particular one. Means all are in group MGH. Employee                                               company Rahul                                                     

  • How does the icon get created for a saved file

    In my program I allow saving files using JFileChooser and ActionListener. In the constructor of the main class which extends JFrame I also set an icon by saying: this.setIconImage(new ImageIcon("image.jpg").getImage()); This does not only set an icon

  • SAP Netweaver 2004 XI 3.0 SR1

    Hello Everyone, I Have Installed SAP Netweaver 2004 XI 3.0 SR1 Successfully. after that what will do. Please send me post Installation steps. Regards, Suresh.K