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之间的日期时间
怎么做?
答案 0 :(得分:1)
试试这个: 我希望这对你有所帮助,这对我有用......
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);
}
答案 1 :(得分:1)
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();
这将返回以毫秒为单位的差异