Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Get num days between 2 Calendars

Posted on 2006-06-25
4
Medium Priority
?
278 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 120 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Suggested Courses
Course of the Month21 days, 3 hours left to enroll

810 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