标签:style blog java color 2014 io
1 import java.text.*; 2 import java.util.*; 3 public class DateDemo { 4 public static void main(String[] args) throws Exception{ //throws Exception { 5 /*DateFormat df = DateFormat.getDateInstance(); 6 String date ="2014-7-18"; 7 Date d = df.parse(date); 8 System.out.println(d);*/ 9 Scanner sc = new Scanner(System.in); 10 System.out.println("请输入你的出生年月日"); 11 String Date1 = sc.nextLine(); 12 System.out.println("请输入现在的年月日"); 13 String Date2 = sc.nextLine(); 14 DateFormat df = DateFormat.getDateInstance(); 15 Date de1 = df.parse(Date1);//转换成日期类型 16 Date de2 = df.parse(Date2);//转换成日期类型 17 long time1 = de1.getTime();//转换成毫秒 18 long time2 = de2.getTime();//转换成毫秒 19 long time3 = Math.abs(time2-time1)/1000/60/60/24; 20 System.out.println(time3); 21 } 22 }
标签:style blog java color 2014 io
原文地址:http://www.cnblogs.com/fa20091001/p/3852288.html