java2个日期差!

 
 
写道
pattern 格式需要跟 sf.parse(“2013/07/08 9:00:00”); 方法内的参数 格式一致 / 或者 - 要一致 否则会出现 java.text.ParseException: Unparseable date 异常
 n = "yyyy/MM/dd hh:mm:ss";
					SimpleDateFormat sf = new SimpleDateFormat(pattern);
					try {
						Date inventoryDate = sf.parse("2013/07/08 9:00:00");
						Date nowDate = sf.parse("2013/07/08 9:00:00");
						long diff =nowDate.getTime()- inventoryDate.getTime();
						diff = diff / 1000 / 60 / 60 / 24;
						android.util.Log.v("====",diff+" <<<");
					} catch (ParseException e) {
						e.printStackTrace();
					}

 

你可能感兴趣的:(java)