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
Development process Questions

difference
difference  difference b/w java and asp.net 

SQL Question

difference
difference  what's the difference between mysql and sql 

JDBC Questions

difference
difference  difference between hashtable and hashtree 

Java Beginners

Difference
Difference  What Is the difference between JDK & SDK 

JDBC Questions

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 

Java Beginners

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 

Java Beginners

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 

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
 

JavaScript Questions

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

Struts Questions

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

Java Interview Questions

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

Java Server Faces Questions

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

Struts Questions

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

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 

Mobile Applications Questions

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

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

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 

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 

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 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 

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 

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 

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 

Java Beginners

what is the difference between extends and implements
what is the difference between extends and implements  difference between extends and implements 

Java Interview Questions

what is the difference between extends and implements
what is the difference between extends and implements  difference between extends and implements 

DMCA.com