2015-04-19 33 views
0

我如何將dateBirthdateToday設置爲等於我以mm/dd/yyyy格式輸入的值?我想設置簡單值,所以我可以比較它們以得到一個年齡

public class AgeClientFL { 

public static void main(String [] args){ 

    int month, day, year; 

    day = UtilsFL.readInt("Enter birth day: ",false); // String mode 
    month = UtilsFL.readInt("Enter birth month: ",false); 
    year = UtilsFL.readInt("Enter birth year: ",false); 

    SimpleDate dateBirth = new SimpleDate(); 

    day = UtilsFL.readInt("Enter todays day: ",true); // JOptionPane mode 
    month = UtilsFL.readInt("Enter todays month: ",true); 
    year = UtilsFL.readInt("Enter todays year: ",true); 

    SimpleDate dateToday = new SimpleDate(); 




    } 
} 
+1

默認情況下,Java中沒有類'SimpleData'。 – Veluria

+0

你看過你的SimpleDate類的文檔/源代碼嗎? – DNA

回答

0
import java.text.SimpleDateFormat; 
import java.util.Date; 

... 

SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy"); 
Date date = sdf.parse(dateString); 
System.out.println(sdf.format(date)); 

然而,這java.util.Date是不是真的有用,一切都已經過時,你只能使用的getTime()。 java.sql.Date java.util.GregorianCalendar更有用。我會仔細研究一下,你可以很容易地得到年,月,日等。https://docs.oracle.com/javase/7/docs/api/java/util/GregorianCalendar.html

相關問題