How can change my code to can user insert numbers of year and days ?
- by MANAL
I make code to calculate the date of today and the date for two years ago before the day of today and also calculate day before 5 days.
I want user insert the numbers of years and days to make compare between date of today .
import java.util.Date;
import java.util.Calendar;
import java.text.SimpleDateFormat;
import java.util.Scanner;
public class Calendar1
{
private static void doCalendarTime() {
System.out.print("*************************************************");
Date now = Calendar.getInstance().getTime();
System.out.print(" \n Calendar.getInstance().getTime() : " + now);
System.out.println();
}
private static void doSimpleDateFormat() {
System.out.print("*************************************************");
System.out.print("\n\nSIMPLE DATE FORMAT\n");
System.out.print("*************************************************");
// Get today's date
Calendar now = Calendar.getInstance();
SimpleDateFormat formatter = new SimpleDateFormat("E yyyy.MM.dd 'at' hh:mm:ss a zzz");
System.out.print(" \n It is now : " + formatter.format(now.getTime()));
System.out.println();
}
private static void doAdd() {
System.out.println("ADD / SUBTRACT CALENDAR / DATEs");
System.out.println("=================================================================");
// Get today's date
Calendar now = Calendar.getInstance();
Calendar working;
SimpleDateFormat formatter = new SimpleDateFormat("E yyyy.MM.dd 'at' hh:mm:ss a zzz");
working = (Calendar) now.clone();
working.add(Calendar.DAY_OF_YEAR, - (365 * 2));
System.out.println (" Two years ago it was: " + formatter.format(working.getTime()));
working = (Calendar) now.clone();
working.add(Calendar.DAY_OF_YEAR, + 5);
System.out.println(" In five days it will be: " + formatter.format(working.getTime()));
System.out.println();
}
public static void main(String[] args) {
System.out.println();
doCalendarTime();
doSimpleDateFormat();
doAdd();
}
}
help me .