android 时间大小比较

private void TimeCompare(){
        //格式化时间
        SimpleDateFormat CurrentTime= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String date1="2015-01-25 09:12:09";
        String date2="2015-01-29 09:12:11";
        try {

            Date beginTime=CurrentTime.parse(date1);
            Date endTime=CurrentTime.parse(date2);
            //判断是否大于两天
            if(((endTime.getTime() - beginTime.getTime())/(24*60*60*1000))>=2) {
                Log.v("hi","大于两天");
            }else{
                Log.v("hi","小于两天"); 
                }

        } catch (ParseException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        }

 

你可能感兴趣的:(Android,应用,移动开发)