Home Answers Viewqa Java-Beginners Difference in two dates

 
 


Gagandeep
Difference in two dates
2 Answer(s)      4 years and 5 months ago
Posted in : Java Beginners

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 Pages:
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
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
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
calculate difference between two time in jsp
calculate difference between two time in jsp  How to calculate difference between two dates
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
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
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
Mysql Time Difference Function
difference between any two dates. Understand with Example The Tutorial describe... the time difference between any two consecutive dates. TimeDiff('Year1 Time1... dates.     Query to Time Difference Function mysql> SELECT
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
PHP Date compare the dates, PHP Compare dates example
difference dates in PHP echo "<b>PHP Date compare example</b><... 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
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
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
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>
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
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
JavaScript Date Difference
; In this section, we are going to determine the difference between two dates...;"); document.write("Difference between two dates is :"+   Math.ceil... to set two dates i.e current date and the date specified. Then we have used
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
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 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> <
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
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
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
Ask date difference
" +curyear + " Thn " ); }   Here is an example that accepts two dates from the user and calculates the date difference in terms of days. import
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
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
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
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
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
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... of days between two dates: return (int)( (d2.getTime
Flex difference
Flex difference  Hi.... please tell me about What is the difference between Flex 2.0 and Flex 3.0? Thanks  Ans: There are some... 2. flex ajax bridge 3. Two newly added component Advanced datagrid and OLAP
Comparing two Dates in Java with the use of after method
Comparing two Dates in Java with the use of after method... to compare two date objects in Java programming language. For comparing...() method to compare the dates. firstDate.after(secondDate); firstDate.after
difference b/w == and equals()
difference b/w == and equals()  what is the difference between == operator and equals()   Hi Friend, The == operator checks if the two objects were actually the same object. This operator looks at the actually memory
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
method and function difference
method and function difference  so far, I understand that method and function are the same thing... but is there any difference between the two terms? Please explain me if both are different terms. Thanks in advance
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 between forward and sendRedirect
Difference between forward and sendRedirect  What's the difference between forward and sendRedirect?   RequestDispatcher.forward() and HttpServletResponse.sendRedirect() are the two methods available for URL redirecting
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
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
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

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.