gena
BAN USERi suspect you need to use Calendar:
import java.util.*;
public class DatesCompare {
private static Calendar calendar = Calendar.getInstance();
public static int compare(Date date1, Date date2) {
calendar.setTime(date1);
int m1 = calendar.get(Calendar.YEAR) * 12
+ calendar.get(Calendar.MONTH);
int d1 = calendar.get(Calendar.DAY_OF_MONTH);
calendar.setTime(date2);
int m2 = calendar.get(Calendar.YEAR) * 12
+ calendar.get(Calendar.MONTH);
int d2 = calendar.get(Calendar.DAY_OF_MONTH);
switch (Math.abs(m1 - m2)) {
case 0: // the same month -> dates are too close to each other
return -1;
case 1: // adjacent months
if (d1 == d2) // exactly one month difference!
return 0;
if (m1 < m2)
if (d1 < d2)
return 1; // dates are too far away from each other
else
return -1; // dates are too close to each other
else if (d1 > d2)
return 1; // dates are too far away from each other
else
return -1; // dates are too close to each other
default:
return 1; // dates are too far away from each other
}
}
}
Repsamuelcsmith700, Accountant at Absolute Softech Ltd
Je suis chef d'équipe de support Office dans une entreprise Action Auto. Je suis également rédacteur de blog. J ...
Repjuanajcox4, Python Developer at Axiom Sources
I have 2 years of experience in designing and implementing computer algorithms or models for creating, displaying, and processing various ...
Repkevinlmoses, Animator at Accenture
I am Experienced Building Manager who is an expert in public and industrial safety with a preventative mindset against fire ...
Repomarcdei, Android Engineer at Abs india pvt. ltd.
I'm Omar. I am working as a Mail carrier in Manning's Cafeterias company. I love to learn and ...
Repjohnagragg0, cox customer service at Deloitte Consulting LLP
I am friendly, I am a hard worker, even through difficult circumstances, I want to know about How to identify ...
Repcharlespladd, Android Engineer at Abs india pvt. ltd.
I am Charles from Pascoag USA. I have strong knowledge of pain management systems. And I have experience in providing ...
Repmyershllims, abc at ASAPInfosystemsPvtLtd
Hiii, I am Myers and I am from Elizabeth. I am working as a Product designer designing most things I ...
Date is wrapper around long time
- gena April 11, 2013it may be unix time or different time - but it is point on time axe
Different calendars treat this point time very differently when they deduce year, month and date
My point is very simple - it is very undedfinrd question and if you want to answer it right you have to take into account a LOT