如何在android中找到字符串格式的两个日期之间的差异


Calendar zCalendarL = Calendar.getInstance(); 
SimpleDateFormat zDateFormatL = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
String DateTime="2013/02/15 15:05:01";
String zUpdatedDateTimeG =zDateFormatL.format(DateTime);
String zCurrentDateTimeL=zDateFormatL.format(zCalendarL.getTime());

我需要知道zCurrentDateTimeL和zUpdatedDateTimeG 之间的日期时间

怎么做?

试试这个:我希望这将对你有所帮助,这是为我工作的…

        private void getDifference(java.util.Date startTime,
            java.util.Date endTime, java.util.Date eartime,
            java.util.Date curtime) {
        Calendar startDateTime = Calendar.getInstance(TimeZone
                .getTimeZone("GMT-5:00"));
        startDateTime.setTime(startTime);
        Calendar endDateTime = Calendar.getInstance();
        endDateTime.setTime(endTime);           
        long milliseconds1 = startDateTime.getTimeInMillis();
        long milliseconds2 = endDateTime.getTimeInMillis();
        long diff = Math.abs(milliseconds1 - milliseconds2);
        long seconds = diff / (1000);
              }
Calendar zCalendarL = Calendar.getInstance(); 
SimpleDateFormat zDateFormatL = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
String DateTime="2013/02/15 15:05:01";
Date d = zDateFormatL.parse(DateTime);
long diff = System.currentTimeMillis() - d.getTime();

这将返回以毫秒为单位的差值

相关内容

  • 没有找到相关文章