输入日期计算天数

 
  
package ch3;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;

public class Text {
public static void main(String[] args) throws ParseException {
	Scanner s = new Scanner(System.in);
	System.out.println("请输入年月日(2013-2-10):");
	String str =s.next();
	Date date = new Date();
	long a = date.getTime();
	SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd");
	long b = sd.parse(str).getTime();
	int success = (int) ((a-b)/(1000*60*60*24));  //1000毫秒*60分钟*60秒*24小时 = 天
	     System.out.print("距离输入的的年月日有:"+success+"天");
	
	
}
}


 
  
 
 

你可能感兴趣的:(java学习)