两个字符串时间算时间差

来源:互联网 发布:有没有mac的ps教材 编辑:程序博客网 时间:2024/06/09 06:37
SimpleDateFormat inputFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");        Date startDate = null;        Date endDate = null;        try {            startDate=inputFormat.parse("2017-09-01 20:00:00");            endDate=inputFormat.parse("2017-09-02 20:00:00");        } catch (ParseException e) {            e.printStackTrace();        }        //得到两个日期对象的总毫秒数        long firstDateMilliSeconds = startDate.getTime();        long secondDateMilliSeconds = endDate.getTime();        //得到两者之差        long firstMinusSecond = secondDateMilliSeconds - firstDateMilliSeconds;        //得到秒        long totalSeconds = (firstMinusSecond / 1000);
原创粉丝点击