Home Discussion Discuss: Date Difference

  • Thank youMark February 23, 2012 at 2:05 PM

    saved me the time of developing an algorithm

  • Date Difference ProblemArun R T April 3, 2012 at 2:33 PM

    In your code import java.util.Calendar; public class DateDifferent{ public static void main(String[] args){ Calendar calendar1 = Calendar.getInstance(); Calendar calendar2 = Calendar.getInstance(); calendar1.set(2007, 01, 10); calendar2.set(2007, 07, 01); long milliseconds1 = calendar1.getTimeInMillis(); long milliseconds2 = calendar2.getTimeInMillis(); long diff = milliseconds2 - milliseconds1; long diffSeconds = diff / 1000; long diffMinutes = diff / (60 * 1000); long diffHours = diff / (60 * 60 * 1000); long diffDays = diff / (24 * 60 * 60 * 1000); System.out.println("\nThe Date Different Example"); System.out.println("Time in milliseconds: " + diff + " milliseconds."); System.out.println("Time in seconds: " + diffSeconds + " seconds."); System.out.println("Time in minutes: " + diffMinutes + " minutes."); System.out.println("Time in hours: " + diffHours + " hours."); System.out.println("Time in days: " + diffDays + " days."); } } I substitute calendar1.set(2012, 03, 31); calendar2.set(2012, 04, 03); Time in days: 2 days. "But current is 3"

  • Does not workNot May 1, 2012 at 4:09 PM

    It does not work correctly from month to month!

  • what is the modification required?pooja September 5, 2012 at 3:45 PM

    long diff = milliseconds2 - milliseconds1; but it gets the difference based on 12 hr clock so it returns negative when send time is prior to 1st time while calculating the difference. so what is the modification required in order to get proper time difference value without negative value.

Post your Comment

Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
Related Articles
JDBC Questions

difference  difference between hashtable and hashtree 

SQL Question

difference  what's the difference between mysql and sql 

Development process Questions

difference  difference b/w java and asp.net 

Java Beginners

Difference  What Is the difference between JDK & SDK 

JDBC Questions

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 

Java Beginners

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 

Java Beginners

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 

Applet Questions

difference - Applet
difference  what is the difference in between awt and swing package... and what is the difference in between frame,panel  Hi Friend.... Difference between frame and panel: 1)A frame is a resizable movalble window 

Flex Questions

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 advantages of Flex3.0 over Flex 2.0 they are following: 1. Faster compilation time 

EJB Questions

difference - EJB
difference  difference between stateful and stateless beans   Hi friend, Stateful Beans *)Stateful beans are also Persistent session beans. *)They are designed to service business processes that span multiple 

JSP Servlet Questions

time difference

Struts Questions

Difference between DispatchAction and LookupDispatchAction
Difference between DispatchAction and LookupDispatchAction  What is the Difference between DispatchAction and LookupDispatchAction 

JavaScript Questions

difference between SessionState and ViewState
difference between SessionState and ViewState  What is the difference between SessionState and ViewState 

Struts Questions

difference between ForwardAction and IncludeAction
difference between ForwardAction and IncludeAction  What is the difference between ForwardAction and IncludeAction 

Java Server Faces Questions

Difference between struts and JSF
Difference between struts and JSF  What is the difference between struts and JSF 

Java Interview Questions

difference between == and === operators?
difference between == and === operators?  Is (====) operator available in java or not? difference between 

Mobile Applications Questions

Difference between 3d and 4d
Difference between 3d and 4d  what is the difference between 3d and 4d 

Java Beginners

What is the difference between the >> and >>> operators?
What is the difference between the >> and >>> operators?   hi, What is the difference between the >> and >>> operators? Thanks 

SQL Question

difference between varchar & varchar2?
difference between varchar & varchar2?  What is the difference between varchar & varchar2 

Java Interview Questions

what is the difference in java and j2ee
what is the difference in java and j2ee  Hi, Please tell me: 1. What is the difference between Java and Core Java and 2. Difference between Java and J2EE 


Mysql Difference
Mysql Difference       Mysql Difference is used to return the records that are the outcome of difference between the records in a table. Understand with Example The Tutorial 

SQL Tutorial

Mysql Difference
Mysql Difference       Mysql Difference is used to return the records that are the outcome of difference between the records in a table. Understand with Example The Tutorial 

SQL Question

Difference between Mysql and SQL
Difference between Mysql and SQL  hello, What is the difference between Mysql and SQL??   hii, SQL is structural quary language but mysql is database package 

Java Interview Questions

Difference between Timer and Thread?
Difference between Timer and Thread?  Can anyone tell me about the difference between Timer and Thread, Why we need to have Timer in case we have Thread implimentation startegy in Java 

Java Interview Questions

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 

JSP Interview Questions

Difference between request.getRequestDispatcher() and context.getRequestDispatcher()
Difference between request.getRequestDispatcher() and context.getRequestDispatcher()  What is the difference in using request.getRequestDispatcher() and context.getRequestDispatcher()?   request.getRequestDispatcher 

JSP Interview Questions

Difference between JSP and Servlets
Difference between JSP and Servlets  What is the difference between JSP and Servlets ?   JSP is used mainly for presentation only. A JSP can only be HttpServlet that means the only supported protocol in JSP is HTTP 

Java Beginners

difference between lock and synchronization
difference between lock and synchronization  Hi, I am new in java please anyone tell me difference between lock and synchronization in java. its urgent. Thank in advance   Please visit the following link: Lock 

Java Beginners

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 

Java Beginners

Difference between SCJP Exams
Difference between SCJP Exams  What is the differences between SCJP 5 (310 - 055) exam and SCJP 6 (310 - 065) exam??? Thank You In Adv