Solved

Get num days between 2 Calendars

Posted on 2006-06-25
4
256 Views
Last Modified: 2010-03-31
I have two Calendar objects, with their time fields (hour, minute, second, millisecond) all set to zeros. I want to get the days difference between these two objects.

Example:

Calendar 1: 2006-06-26
Calendar 2: 2006-06-27
results: -1

Calendar 1: 2006-06-26
Calendar 2: 2006-06-25
results: 1
0
Comment
Question by:yongsing
  • 2
  • 2
4 Comments
 
LVL 10

Expert Comment

by:mukundha_expert
ID: 16981078
Use compareTo() to get the difference in time in Milliseconds,

from this you can get the difference of days,

int time = cal1.compareTo(cal2);

int days = time / 1000*60*60*24

0
 
LVL 10

Accepted Solution

by:
mukundha_expert earned 30 total points
ID: 16981086
sorry am not sure about compareTo(),

try this

long cal1time = cal.getTimeinMillis()
long cal2time = cal2.getTimeinMillis()

long diff = cal1time - cal2time;

int days = diff / 1000*60*60*24
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 16981168
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 16981169
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
tomcat startup error 5 106
Java: The Public Class Main 4 32
Java syntax, or is it Selenium 6 30
Delphi Firemonkey: if the Sms contain special characters it won't send it 3 44
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question