Compute the Difference between Two Dates Using DateAdd

From Java Example Source Code

Jump to: navigation, search

Contents

[edit] Overview - Compute the Difference between Two Dates Using DateAdd

This Java program shows how to compute the difference between two dates.

[edit] Java Source Code

  • Package: example.calendardate
  • File: DateAdd.java
package example.calendardate;
 
import java.util.Date;
 
/**
 * DateAdd -- compute the difference between two dates.
 */
public class DateAdd {
    public static void main(String[] av) {
	// +
	/** Today's date */
	Date now = new Date();
 
	long t = now.getTime();
 
	t -= 700 * 24 * 60 * 60 * 1000;
 
	Date then = new Date(t);
 
	System.out.println("Seven hundred days ago was " + then);
	// -
    }
}

[edit] What Result You Can Get

Run the program, you will get:


Seven hundred days ago was Mon Aug 04 21:46:11 PDT 2008

[edit] Required External Libraries and/or Files for this Java Example

Need nothing.


[edit] How to Run this Java Example Program

We recommend running this Java example program with Eclipse.

For assistance in working with Eclipse, please see How to Run Java Program with Eclipse.

It's fairly easy.



[edit] Question & Answer

Any question?

Click edit and post your question or answer here.


Personal tools