How do you find the difference in no. of days between 2 dates?

How do you find the difference in no. of days between 2 dates ?

There are 2 way to solve this: using java.util.GregorianCalendar or java.util.Date (like jesper1 suggested), depending what kind of solution You need:
        GregorianCalendar gc1 = new GregorianCalendar(2001, 01, 01, 23, 00, 00);
        GregorianCalendar gc2 = new GregorianCalendar(2001, 01, 03, 10, 00, 00);
        // 1st way using GregorianCalendar
        int diff1 = gc1.get(GregorianCalendar.DATE) - gc2.get(GregorianCalendar.DATE);
        System.out.println("Differnce: " + diff1);
        // 2nd way using Date
        int diff2 = (int)(gc1.getTime().getTime() - gc2.getTime().getTime()) / (24 * 60 * 60 * 1000);
        System.out.println("Differnce: " + diff2);Note: There are 2 days between the given dates, but exactly 1 day and 11 hours.
The first solution returns "-2", the second returns "-1".
(... and a 4th posting also won't help ...)

Similar Messages

  • Finding the difference in no. of days between 2 dates

    Finding the difference in no. of days between 2 dates

    http://search.java.sun.com/Search/java?col=javafrm&qp=%2Bforum%3A54&qt=days+difference&x=12&y=11

  • 1.) How do you find the dictionary in Apple Mail Program?  2.) How do you add another dictionary?

    1.) How do you find the dictionary in Apple Mail Program?  2.) How do you add another dictionary?

    Hello James!
    I do not have any ABAP Instance, only the JAVA one.
    Therefore the ABAP transactions are quite useless.
    The problem tables are created by people working on the CAF layer.
    They have developed and deployed some homemade applications and this is leftovers from their development in some kind of way.
    Anyone with any ideas?
    Could it be that (yet) some special Portal Dictionary Role needs to be asigned to the Administrator?
    /Lasse

  • How do you tell the difference between a genuine USB to Lightning cable? I spoke to two different operators at Apple Support. One said that it has Designed in California Made in China and the serial number on it, and the other operator said it didn't

    How can you tell the difference between a genuine Apple lead and the cheap, or sometimes not so cheap imitations? I spoke with two people at Apple Support - one said that it has Designed in California Made in China and the serial number stamped on it, and the other said it didn't. Come on guys, how are we supposed to tell if you can't? I'd really like to know how to identify my lead amongst my daughter's gazillion fakes?

    All my cables are genuine either with the devices or from Apple retail Store I have never found a serial number on any regardless of which length ,I have all three lengths
    In fact they have nothing printed at all only a USB logo at relevant end

  • HT204003 How do you find the passbook enabled apps once you use passbook???

    How do you find the list of passbook enabled apps once you start using passbook???

    http://www.macrumors.com/2012/09/19/passbook-enabled-apps-start-arriving-on-app- store/

  • How would you find the pitch period of a sound signal?

    Hi
    I have a few questions and i would like if somebody could help me even with the smallest comment on this.
    How would someone be successfully estimate the pitch period (fundamental frequency) of a 5 second sound file?How would you successfully distinguish the voiced from the unvoiced parts and how would you make sure you dont mix voiced/unvoiced sections? Finally how can you find the exact points where the pitch is at its peak throughout the signal?
    Any help/comment/suggesion would be much appreciated

    Hello Madgreek,
    After some thought I think I may have come up with an algorithm for what we have discussed. Basically, you are interested in knowing the time intervals over which you can observe any given frequency in your signal. As you had suggested, you can examine small windows of your signal and perform FFTs on each of the small windows to determine what frequency content is contained in that window. By examining all of the windows, you will see when particular frequencies are prevalent in the original signal. You'd want to use the smallest allowable window to give you the most resolution, but one that is large enough to cover an entire period of the lowest frequency (so that you don't miss this frequency).
    I have attached an example program that performs this operation. The example performs this analysis on an array that represents audio data. I am basically performing multiple FFTs (for each window) and stacking these FFTs in time to form a 3D plot. By examining the 3D plot, I can then see when in time my frequencies of interest are at their peaks. Rather than graphing these plots, you may work out a different algorithm for programmatically determining and logging these peaks and times. I hope this is what you were looking for!
    Attachments:
    Time Variable FFT.vi ‏250 KB

  • How do you find the phone's mac address for Droid RAZR Maxx HD?

    how do you find the phone's mac address for Droid RAZR Maxx HD?

    Ann154 wrote:
    WalrusM wrote:
    how do you find the phone's mac address for Droid RAZR Maxx HD?
    It is listed under the advanced options for the WiFi settings or About Phone > Status within the phone's settings
    Motorolas list them under About Phone > Status.
    Edit:  Oh, snap!  It is listed in both places.     Nevermind!  Please excuse! 

  • How do you find the word count on MacBook, please?

    How do you find the word count on MacBook, please?

    If you are trying to find word count in a Microsoft Word 2011 documemt, for instance, open the document and go to the Tools menu, selecting Word Count. In Apple's Pages application, open the document and look at the bottom of the page, near the left it will say "X Words" where X is the number.
    Best of luck.

  • I've formatted my PC, how do you find the album you have bought in there on my account again?I've formatted my PC, how do you find the album you have bought in there on my account again?

    I've formatted my PC, how do you find the album you have bought in there on my account again?

    If you reformatted you disk, then you music was deleted.
    Apple only allows one download and advises that purchases are backed up.
    I guess you don't have a backup?
    If not you can recover purchased music from your iPod if you have one:
    http://discussions.apple.com/thread.jspa?messageID=11857427&#11857427
    If you can't do either, try contacting customer service and explain the situation, but they are not obliged to help you.
    http://www.apple.com/support/itunes/

  • How do you find the iPad phone number for cellular data?

    How do you find the iPad phone number for cellular data?

    I know this post was a long time ago but people still seem to be viewing it.
    Quickest way:
    Via the iPad on 3G, go to http://m.telstra.com. The service number is then displayed and you are given the option to recharge.

  • If unboxed how could you tell the difference between refurbished imac and new imac?

    If unboxed how could you tell the difference between refurbished imac and new imac?

    Besides all of that, you can purchase Apple Care which will extend your warranty to 3 years just like you can on a brand new iMac.
    If you're considering a "refurbished" iMac, buy it ONLY from Apple.  I believe it's your best bet.

  • HT5312 How can you find the link to get a rescue email?

    How can you find the link to get a rescue email?
    I am not a regular user - and wonder why????
    Been at this for hours, can't remember questions, support sends you to the questions you can't answer or I would have the first time, or a promise of a link which doesn't seem to exist!!
    Now locked out!

    You need to contact Apple, either through the link in that article or by phoning them and asking for the Account Security team.
    (80167)

  • How do you find the replies to the questions I asked?

    ''locking this as a duplicate - https://support.mozilla.com/en-US/questions/822449''
    How do you find the replies to the questions I asked?

    Click the '''My Contributions''' link after you log in. See screenshot.

  • How to quickly find the difference of two version of RPD?

    Hi all,
    Does anyone have good idea about quickly finding the difference of two versions of RPD in the project?
    Regards,
    Anne

    This might be of help to you
    http://varanasisaichand.blogspot.com/2010/03/how-to-merge-two-repositories.html
    http://www.rittmanmead.com/2010/07/obiee-11gr1-incremental-patches-to-the-rpd/
    Cheers,
    KK
    Edited by: Kranthi.K on Dec 7, 2011 9:41 PM

  • How do you find the number of lines in a file?

    I need to count how many lines there are in a file, I am using a BufferedReader to read in the data, but how can I find the number of lines?
    Thanks

    That depends. How do you define a line? Is it a specific number of
    characters, a String that's terminated by a newline character or some
    combination thereof?

Maybe you are looking for

  • My Ipod touch is recognized by itunes, but not by my computer!

    My hard drive recently crashed, and I had to get a new one. I lost all my songs, so I am trying to transfer them to my new harddrive, but windows only recoginzes my ipod touch as a camera, so I can't get to my songs. Help?

  • How to get tem level text of PO???

    Dear all, I want to get the data for Item level text of PO. But not able with the function read_ text as in header level text. So please tell me how I can get for tem level text of PO. Thanks in advance. Sachin Gautam

  • Survey on QWERTY slide phone usage

    Hi, I'm a cell phone designer and I need your help. We're currently developing a new model and we heard an interesting "rumor" which is that some teenagers use their QWERTY slide phone as a wallet. For example, they put their driver's license or mone

  • How to block certain web pages?

    This web page opens by itself in a new tab and starts talking. http://malwarewarning.net/ It is an obvious scam. I have tried deleting cookies. Is their any way to get rid of this? It is very annoying.

  • Adding ITems in Personalizations

    Could anyone tell me what the fields should be when clicking on the Personalizations Page - then add an item - if I want to add a checkbox?