Difference in two dates

Difference in two dates

View Answers

January 6, 2009 at 11:06 PM

Hi friend,

Please implement following code. I hope that,this code will help you.


import java.util.*;
import java.util.GregorianCalendar;

// compute the difference between two dates.

public class DateDiffDemo {
public static void main(String[] args) {
//The date at the end of the last century
Date date = new GregorianCalendar(2000, 11, 31, 23, 59).getTime();
Date today = new Date();
// Get msec from each, and subtract.
long diff = today.getTime() - date.getTime();

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




----------------------------------

Thanks

January 6, 2009 at 11:09 PM









Related Tutorials/Questions & Answers:
calculate difference between two dates
the difference between the two dates...calculate difference between two dates  hi, I was actually working on to calculate the number of days between two dates of dd/mm/yyyy format
Difference in two dates - Java Beginners
on that. The thing is, that I need to find the difference between the two dates in JAVA... the difference between two dates. public class DateDiffDemo { public static...Difference in two dates  Hello there once again........ Dear Sir
Advertisements
Hi .Difference between two Dates - Java Beginners
Hi .Difference between two Dates  Hi Friend.... Thanks for ur Very good response.. Can u plz guide me the following Program.... difference between two dates.. I need to display the number of days by Each Month
to calculate the difference between two dates in java - Java Beginners
to calculate the difference between two dates in java  to write a function which calculates the difference between 2 different dates 1.The function should accept 2 different dates (in the format dd/mm/yyyy hh:mm:ss AM/PM) 2.The
display dates between two dates - Java Beginners
display dates between two dates  hi can any one help me to writing this code, i need to store the dates between to dates so that i can retrive the data from the db using theses dates. its urgent pls tell me as possible
calculate difference between two time in jsp
calculate difference between two time in jsp  How to calculate difference between two dates
mysql difference between two numbers
mysql difference between two numbers  How to get total bate difference between two dates for example 1/01/2012 and 1/02/2012 in MYSQL?   ..., '01/02/2012', 103))   DATEDIFF() in MYSQL always returns the difference
Mysql Time Difference Function
difference between any two dates. Understand with ExampleADS_TO_REPLACE_1 The Tutorial... that return you the time difference between any two consecutive dates. TimeDiff... any consecutive dates.  ADS_TO_REPLACE_2   Query to Time Difference
Comparing two dates in java
Comparing two dates in java In this example you will learn how to compare two dates in java.  java.util.Date provide a  method to compare two dates... date. The example below compares the two dates. import
Java Swing Date Difference
Java Swing Date Difference In this tutorial, you will learn how to find the difference between two dates. Here is an example that accepts two dates from... the following method that calculates the date difference in terms of days
days between two given dates using PHP
days between two given dates using PHP  How can we know the number of days between two given dates using PHP?   Hi friends, Example: <html> <head> <title>Number of days between two
Comparing two Dates in Java
Comparing two Dates in Java       In  this example we are going to compare two date objects using java.util.Date class. For comparing dates, we will be using compareTo
list of all months between two dates in java
list of all months between two dates in java  Hi, I want to get list of all months with year between two dates. How to do this in Java? Thanks   Hi, This is the example code which can be used: package test.app
list of all months between two dates in java
list of all months between two dates in java  Hi, I want to get list of all months with year between two dates. How to do this in Java? Thanks   Hi, This is the example code which can be used: package test.app
JavaScript check if date is between two dates.
JavaScript check if date is between two dates.  Check if date is between two dates?   <html> <head> <title>Date before...;/head> <body> <h2>Check if date is between two dates</h2>
Javascript calculate number of days between two dates
Javascript calculate number of days between two dates In this tutorial, you will learn how to calculate number of days between two dates.For this, you need... using Date.getTime() function. Once both Dates have been converted, subtracting
Two Dates code validation - Date Calendar
Two Dates code validation  Hi Sir.I am using calender for two text... dates."); datefield.focus(); return false; } else { return true...(date2.value)) { alert("The dates are valid."); } else { if (date1.value
How to select Data Between Two dates in Java, MySQL
How to select Data Between Two dates in Java, MySQL  How to select Data Between Two dates in Java, MySQL? Thanks in advance.   http://www.v7n.com/forums/coding-forum/294668-how-select-data-between-two-dates-php
Comparing two Dates in Java with the use of before method
Comparing two Dates in Java with the use of before method... of comparing dates you have seen how to use after() method in java class for comparing two dates. In  this example we are going to compare two date objects
calculate difference of two times and express it in terms of hours
calculate difference of two times and express it in terms of hours  i need jsp code to find out the difference of two times in format hh:mm:ss...(); } } } The above code parse two times and ouputs the difference between two times in terms
calculate difference of two times and express it in terms of hours
calculate difference of two times and express it in terms of hours  i need jsp code to find out the difference of two times in format hh:mm:ss...(); } } } The above code parse two times and ouputs the difference between two times in terms
calculate difference of two times and express it in terms of hours
calculate difference of two times and express it in terms of hours  i need jsp code to find out the difference of two times in format hh:mm:ss...(); } } } The above code parse two times and ouputs the difference between two times in terms
Jdbc connectivity in java to oracle for retrieving data between two dates
Jdbc connectivity in java to oracle for retrieving data between two dates  Dear Sir, I Need a program in which i want to retrieve the data b/w two dates from the database table. I am using combo box to get the date. Problem
calculate difference of two times and express it in terms of hours
calculate difference of two times and express it in terms of hours  i need jsp code to find out the difference of two times in format hh:mm:ss and want to round off the result to a hour value.it's very urgent.plz someone help me
calculate difference of two times and express it in terms of hours
calculate difference of two times and express it in terms of hours  i need jsp code to find out the difference of two times in format hh:mm:ss and want to round off the result to a hour value.it's very urgent.plz someone help me
display diffrence between two dates in a text box - JSP-Servlet
display diffrence between two dates in a text box  i have these set of codes // String di=request.getParameter("timestamp2"); String d2=request.getParameter("timestamp3"); SimpleDateFormat formater=new SimpleDateFormat("dd-mm
Date Difference
Date Difference       This example learns how to make the difference between two dates and how... Object class and makes a difference between a Date object and a set of integer
How to calculating time difference bewteen two countries using country name?
How to calculating time difference bewteen two countries using country name?  How to calculate the time difference between two countries. Example if i pass India and America, then the program should return the time difference
How can we know the number of days between two given dates using PHP?
How can we know the number of days between two given dates using PHP?  How can we know the number of days between two given dates using PHP
what is difference between one-way data binding and two-way data binding?
what is difference between one-way data binding and two-way data binding?  what is difference between one-way data binding and two-way data binding? Thanks
difference
difference  difference between hashtable and hashtree
difference
difference  what's the difference between mysql and sql
difference
difference  difference b/w java and asp.net
Comparing Dates in Java
Comparing Dates in Java       This example illustrates you how to compare two dates. Generally dates... two given dates. To compare dates the given program is helpful for application
validation on dates - Java Beginners
validation on dates  how to find difference in days between two dates in java.  Hi Friend, Please visit the following link: http://www.roseindia.net/java/java-get-example/number-days-between.shtml Thanks
Difference
Difference  What Is the difference between JDK & SDK
difference
difference    what is the difference between the JDBC-ODBC bridge, the Native-API-Partly-Java driver, and the JDBC-Net-All-Java Driver is the placement of the database access libraries   Please visit the following link
Comparing two Dates in Java with the use of after method
Comparing two Dates in Java with the use of after method       In  this example we are going to compare two date objects in Java programming language. For comparing
difference
difference  difference between thread and process in java   Difference between Process and Thread: 1)Process is a program under execution whereas Thread is a part of program. 2)Process are heavy weight programs which
difference
difference  difference between Method Overloading and method Overriding   Difference between Method Overloading and Method Overriding: Overriding is the concept of having functions of same name and signature
mysql between dates not between dates
mysql between dates not between dates  I am trying to list the data between dates and not between dates using join method ..but that not working for me
comparing dates objective c
comparing dates objective c  Comparing two different dates in Objective C.   if( [date isEqualToDate:otherDate] ) NSLog(@"%@ is equal to %@",date,otherDate);   Objective C NSString Date Example
How to calculate Date Difference in Java?
How to calculate Date Difference in Java?  Hi, I have two dates variable. How to calculate Date Difference in Java? Thanks   Hi, You can use the Calendar class for calculating the date difference in Java. Get data
Java get number of days between dates
the number of days between the two described dates. In order to get the number of days between two dates, the given example has set two dates by using... returns the number of days between two dates:ADS_TO_REPLACE_2
Comparing the File Dates
Comparing the File Dates       This java example will help you to compare the dates of files. In java we have the option to compare two or more files. This is useful when we have
javascript date difference in years
javascript date difference in years  I want to find the difference between two dates with respect to years. I am using javascript. Please help.  ... year difference by subtracting the two
JavaScript Date Difference
; In this section, we are going to determine the difference between two dates... the difference between two dates in days: Math.ceil((date.getTime...;"); document.write("Difference between two dates is :"+  
PHP Date compare the dates, PHP Compare dates example
to compare two difference dates in PHP echo "<b>PHP Date compare... The PHP Date compare the dates example code In this PHP Compare dates example, we are describing the code to compare the dates. In the php program we have
javascript date difference in months
javascript date difference in months  How can I find the difference between two dates in terms of months using javascript?   <html>... difference in month : "+monthDiff); </script> </head> </html>
javascript date difference in days.
javascript date difference in days.   I want to find the difference between two dates in terms of days. I am using javascript. Please help.  ...); document.write("Number of day difference : "+dayDiff); </script> <

Ads