Re: Getting Date Difference in Java.



> 1. How do I get the date in java in a specific format (in any format I
> choose). What is the best object for this.
Look at the SimpleDateFormat class.

> 2. How do I get the difference in 2 dates, which should give me in number
> of days.
Look at Calendar.getTimeInMillis() method. It provides a number of
milliseconds since January 1, 1970.

You should code something like :

static int MILLIS_IN_DAY = 1000 * 60 * 60 * 24;
int diffInMillis = cal1.getTimeInMillis() - cal2.getTimeInMillis();
double diffInDays = diffInMillis / MILLIS_IN_DAY;

HTH,
Christophe
.



Relevant Pages

  • Re: Scatter/Gather in Java or Javascript & html (Dynamic class loading?)
    ... part in Java. ... to and from a text format. ... I'll send it the class name or filename how does one's Applet ... "Jones" (string value) ...
    (comp.lang.java.programmer)
  • Re: What is the preferred way to parse messages out of a log?
    ... format, provide searching and message grouping by the dialogID. ... in Java 1.5 to selectively extract values. ... > Trunk Group ID: 00000001 ... If you are comfortable with Java tools for XML you might look into ...
    (comp.lang.java.help)
  • Libidn 1.15
    ... ** java: ... 'GNU Libraries' section to the 'Software libraries' and 'Invoking idn' ... GNU Libidn is a fully documented implementation of the Stringprep, ... http://www.gnu.org/software/libidn/manual/libidn.html - HTML format ...
    (gnu.announce)
  • Re: Efficient format for huge amount of data
    ... it was important for me to have a format that a human ... and other tools that make a binary representation easier to ... best served by a relational database, as those are very good at ... Java, Cocoa, WebObjects and Database consulting for the life sciences ...
    (comp.lang.java.programmer)
  • RE: RH 7.2, J2RE 1.4 and Netscape 7.1
    ... The reason for some problems between 1.4x and 1.4.2 are class file ... format changes. ... I have had multi issues with some of my prebuilt java ... Netscape may even be doing that. ...
    (RedHat)