题目:利用Calendar类计算自己的出生日期距今天多少天,再将自己的出生日期利用SimpleDateFormat类设定的格式输出显示。
package nkk; import java.util.*; import java.text.*; public class text { public static void main(String[] args) { Scanner r = new Scanner(System.in); int y= r.nextInt(); int m = r.nextInt(); int d = r.nextInt(); System.out.println(y+"年"+m+"月"+d+"日"+"出生日期"); Calendar Now = Calendar.getInstance();//获取当天日期 Calendar riqi = Calendar.getInstance();//获取生日日期 riqi.set(y, m-1, d); //获取生日日期 long time = riqi.getTimeInMillis(); long time1 = Now.getTimeInMillis(); long days_Mill = (time1-time)/(1000*60*60*24); Long days = Long.valueOf(String.valueOf(days_Mill)); System.out.println("一共多少天:"+days+"天"); SimpleDateFormat duo = new SimpleDateFormat("出生日期:yyyy年MM月dd日"); System.out.println(duo.format(riqi.getTime())); } }