Hello good people of the world,
I seem to be having a problem with how to make comparisons of dates using the Gregorian calendar objects. i want to find out if there is a way in which i can achieve it.the idea is make comparisons between the current date with a date that wud be produced within a 2 week time frame.To achieve this i set back the system time.but so far i've failed to make the comaprison and am getting compilation errors.Where am i going wrong?the code is below.
import java.util.*;
import java.text.*;
class Today {
public static void main(String[] args)
{
String day2 = null;
String day1 = null;
String day3 = null;
day2 = Later(day2);
day1 = Today(day1);
day3 = Then(day3);
if(day1.equals(day1))
{
System.out.println("This the same date "+ day1);
}
else
if (day1.after(day2) && day2.before(day3))
{
System.out.println("This date is after " + day2 + " days");
}
else
{
System.out.println("This date comes after " + day3 + " days");
}
}
public static String Today(String day1)
{
GregorianCalendar today = new GregorianCalendar();
Date t = today.getTime();
DateFormat dft = DateFormat.getDateInstance();
day1 = dft.format(t);
return day1;
}
public static String Later(String day2)
{
GregorianCalendar thisday = new GregorianCalendar();
thisday.add(GregorianCalendar.DATE,7);
Date d = thisday.getTime();
DateFormat df = DateFormat.getDateInstance();
day2 = df.format(d);
return day2;
}
public static String Then(String day3)
{
GregorianCalendar thisday = new GregorianCalendar();
thisday.add(GregorianCalendar.DATE,14);
Date d = thisday.getTime();
DateFormat df = DateFormat.getDateInstance();
day3 = df.format(d);
return day3;
}
}