比如有一时间string = “2009年12月21日 17时03分45秒”
想得到此时间距离当前有几天?最好精确到秒
我想的方案:把当前时间和string都转换成2000年1月1号0时0分0秒多少秒,然后,执行相减,然后换算成天
大家有没有更好的方法??
比如有一时间string = “2009年12月21日 17时03分45秒”
想得到此时间距离当前有几天?最好精确到秒
我想的方案:把当前时间和string都转换成2000年1月1号0时0分0秒多少秒,然后,执行相减,然后换算成天
大家有没有更好的方法??
[code="java"]
String strDate = "2009年12月21日 17时03分45秒";
Date date1 = new SimpleDateFormat("yyyy年MM月dd日 HH时mm分ss秒").parse(strDate);
Date date2 = new Date();
long millSeconds = (date1.getTime() - date2.getTime()); //此处得到毫秒
System.out.println(millSeconds);
long seconds = millSeconds / 1000; //此处为秒数
System.out.println(seconds);
long days = seconds / (3600 * 24); //此处为天数
System.out.println(days);
[/code]