DateDiff -- compute the difference between two dates : Calendar Date « Development Class « Java

Java
1. 2D Graphics GUI
2. 3D
3. Advanced Graphics
4. Ant
5. Apache Common
6. Chart
7. Class
8. Collections Data Structure
9. Data Type
10. Database SQL JDBC
11. Design Pattern
12. Development Class
13. EJB3
14. Email
15. Event
16. File Input Output
17. Game
18. Generics
19. GWT
20. Hibernate
21. I18N
22. J2EE
23. J2ME
24. JDK 6
25. JNDI LDAP
26. JPA
27. JSP
28. JSTL
29. Language Basics
30. Network Protocol
31. PDF RTF
32. Reflection
33. Regular Expressions
34. Scripting
35. Security
36. Servlets
37. Spring
38. Swing Components
39. Swing JFC
40. SWT JFace Eclipse
41. Threads
42. Tiny Application
43. Velocity
44. Web Services SOA
45. XML
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
C# / C Sharp
C# / CSharp Tutorial
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java » Development Class » Calendar DateScreenshots 
DateDiff -- compute the difference between two dates

import java.util.Date;
import java.util.GregorianCalendar;

/**
 * DateDiff -- compute the difference between two dates.
 */
public class DateDiff {
  public static void main(String[] av) {
    /** The date at the end of the last century */
    Date d1 = new GregorianCalendar(200011312359).getTime();

    /** Today's date */
    Date today = new Date();

    // Get msec from each, and subtract.
    long diff = today.getTime() - d1.getTime();

    System.out.println("The 21st century (up to " + today + ") is "
        (diff / (1000 60 60 24)) " days old.");
  }
}



           
       
Related examples in the same category
1. When does the UNIX date get into troubleWhen does the UNIX date get into trouble
2. Trivial class to show use of Date and Calendar objectsTrivial class to show use of Date and Calendar objects
3. Convert longs (time_t in UNIX terminology) to seconds
4. Show use of Calendar objectsShow use of Calendar objects
5. How quickly can you press return
6. Easter - compute the day on which Easter fallsEaster - compute the day on which Easter falls
7. Show use of Calendar get() method with various parameters
8. TimeComputation for processing sqrt and Input and Output operations.
9. Bean to display a month calendar in a JPanelBean to display a month calendar in a JPanel
10. Show some date uses 1
11. Show dates before 1970
12. Compare Dates
13. Compare File Dates
14. Show some calendar calculations
15. The best way to format a date/time is to use
16. Create SimpleDateFormats from a string read from a file
17. DateCalAdd -- compute the difference between two dates
18. Show some date uses
19. Calendar DemoCalendar Demo
20. DateAdd -- compute the difference between two dates
21. Date Format Test Date Format Test
22. Swing: Date Time EditorSwing: Date Time Editor
23. Match DateMatch Date
w__w_w_.__ja___v_a2___s_.__c_om_ | Contact Us
Copyright 2003 - 08 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.