與當前的日期進行比較我應該向用戶詢問他們的年齡,作爲回報,我應該檢查他們已經多少天住了。我試過在這裏搜索,但我無法完全知道如何去做。公曆沒有外部類
條件:將GregorianCalendar日期作爲參數並返回該日期和今天之間的天數差的方法。 我無法爲此使用任何外部類。
這是我未完成的代碼:
public static void main(String[] args) {
int day;
int month;
int year;
int difference;
Scanner scanIn = new Scanner(System.in);
System.out.println("Please enter your birth date.");
System.out.println("Please enter the month you were born in (mm)");
month = scanIn.nextInt();
System.out.println("Please enter the day you were born in (dd)");
day = scanIn.nextInt();
System.out.println("Please enter the year you were born in (yyyy)");
year = scanIn.nextInt();
GregorianCalendar greg = new GregorianCalendar(year, month, day);
difference = getDifference(greg);
month = greg.get(Calendar.MONTH) + 2;
year = greg.get(Calendar.YEAR);
//System.out.println("Year is " + year);
//System.out.println("Month " + month);
}
public static int getDifference(GregorianCalendar greg) {
Calendar now = new GregorianCalendar();
int difference;
System.currentTimeMillis.greg();
difference = greg - now;
return difference;
}
我不明白怎麼去區別呢?
我的教練建議我們用毫秒來解決這個問題,但我已經花了4小時試圖解決這個問題,我不明白這一點。
我如何得到當前的日,月和年?
在發佈之前請耐心搜索Stack Overflow。 –