2017-08-22 84 views
-1

我已經導入了joda libary,並且能夠導入Easy Reader類。不過,我需要幫助格式正確,所以我可以計算在這之間的日子,是的,我與MM/dd/yyyy一起,但我使用了整數。我需要導入其他東西嗎?我對喬達真的很陌生,所以請耐心等待,謝謝。一切似乎工作正常,但我找不到正確的語法,這將幫助我找到兩個日期之間的差異,我找不到它。宣佈開始日期和結束使用喬達時間?

import org.joda.time.DateTime; 
import org.joda.time.DateTimeZone; 
import org.joda.time.LocalDate; 
class starter{ 
public static void BdayPrgm(String args[]){ 

System.out.println("Please Enter Today's Month: "); 
     EasyReader month = new EasyReader(); 
     //this will indentify it as an INT, not a string. 
     //quest is a question btw. 
     todaysmon = month.readInt(); 

     System.out.println("What number is today?: "); 
     EasyReader currentday = new EasyReader(); 
     todayday = currentday.readInt(); 



     System.out.println("What is today's year?: "); 
     EasyReader todayyear = new EasyReader(); 
     year = todayyear.readInt(); 

     System.out.println(""); 

     System.out.println("What is your BdayMonth?: "); 
     EasyReader thatyear = new EasyReader(); 
     bdaymon = thatyear.readInt(); 

     System.out.println("What is your Bday #?: "); 
     EasyReader thatday = new EasyReader(); 
     thatgr8day = thatday.readInt(); 

     System.out.println("What is the bdayyear?: "); 
     EasyReader bdayyear = new EasyReader(); 
     bdayyr = bdayyear.readInt(); 


     int age; 
     age = year - bdayyr; 


     //we can get start date by putting test maybe? 
     DateTimeZone LA = DateTimeZone.forID("America/Los_Angeles"); 
     LocalDate start = new LocalDate(year,todaysmon,todayday); 
     LocalDate end = new LocalDate(year,bdaymon,thatgr8day); 

     int Days; 
     //code isn't compileing below. I don't know what I'm doing wrong. 
     Days.daysBetween(new LocalDate(start),new LocalDate(end)).getDays(); 

     //int days = d.getdays; 

     System.out.println(""); 

     System.out.println(CELEB1+" is going to be "+age+" years old in X days!"); 

}

} 
+1

僅供參考,[Joda-Time](http://www.joda.org/joda-time/)項目現在處於[維護模式](https:/ /en.wikipedia.org/wiki/Maintenance_mode),團隊建議遷移到[java.time](http://docs.oracle.com/javase/8/docs/api/java/time/package-summary .html)類。請參見[Oracle教程](https://docs.oracle.com/javase/tutorial/datetime/TOC.html)。 –

回答

0

int Days; 
Days.daysBetween(new LocalDate(start),new LocalDate(end)).getDays(); 

應該像

int dayCount = Days.daysBetween(start, end).getDays(); 

因爲startend已經LocalDate(多個) nd你想保存通話的結果。此外,您應該只需要一個EasyReader實例。並且,您需要添加

import org.joda.time.Days; 
+0

C:\ Users \ owner \ Desktop \ BdayAssignment> javac * .java starter.java:81:error:找不到符號 int dayCount = Days.daysBetween(start,end).getDays(); ^ 符號:可變天 位置:類起動機 1錯誤 C:\用戶\所有者\桌面\ BdayAssignment>暫停 按任意鍵繼續。 。 。它還沒有編譯過。我試圖找到正確的參數,但它是錯誤的... –

+0

@ PYRO912'import org.joda.time.Days;' –

+0

它的工作原理。謝謝。忘了添加導入 –

相關問題