public static void main(String[] args) throws Exception { liveDay("1997-06-19 00:00:00");//活了多少天 } /** * 此方法获取生存了多少天 * @param live * @throws ParseException * */ public static void liveDay(String live) throws ParseException{ SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Date date=sdf.parse(live); //出生日期 Calendar cl=Calendar.getInstance(); cl.setTime(date); long birthday=cl.getTimeInMillis(); //获取当前时间 long now =System.currentTimeMillis(); int day=(int) ((now-birthday)/(24*60*60*1000)); int year=day/365; System.out.println("活了"+day+"天"); System.out.println("活了"+year+"年"); }