Android中计算两个时间的时间差

Posted by PanMin Blog on November 4, 2016

– layout: post # 使用的布局(不需要改) title: Android中计算两个时间的时间差 # 标题 subtitle: #副标题 date: 2016-11-04 # 时间 author: PanMin # 作者 header-img: img/post-bg-2015.jpg #这篇文章标题背景图片 catalog: true # 是否归档 tags: #标签 - Android —

public static long[] getTimeSpan2(Date date, Date futureDate) {
	long delta = futureDate.getTime() - date.getTime();
	
	long days = delta / (1000 * 60 * 60 * 24);
	long hours = (delta-days*(1000 * 60 * 60 * 24))/(1000* 60 * 60);
	long minutes = (delta-days*(1000 * 60 * 60 * 24)-hours*(1000* 60 * 60))/(1000* 60);
	long seconds = (delta-days*(1000 * 60 * 60 * 24)-hours*(1000* 60 * 60)-minutes*(1000* 60))/1000;
	
	return new long[]{hours,minutes,seconds};
}