public class TestData {
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
// method();
method2();//String-->data
}
public static void method2() throws Exception {
//1.输入出生日期
String date= new Scanner(System.in).nextLine();
//2.开始的天数
//1.创建对象--SimpleDateFormat(String pattern)
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd"); //日期格式指定
//2.Date parse(String text)
Date birthday =sdf.parse(date);//将日期转换为date型
long start= birthday.getTime(); //获取出生日期
long now =System.currentTimeMillis();//获取当前时间的毫秒值ms
System.out.println((now-start)/1000/60/60/24);
}
java测试你活了多少天,string类型转换为date
最新推荐文章于 2021-04-22 15:23:20 发布