public class DateToSecond
{
public static void main(String[] args)
{
Date date = new Date(System.currentTimeMillis())
System.out.println(date.getTime())
}
}
Date类有一个getTime()可以换回秒数,例如:
public class DateToSecond{
public static void main(String[] args)
{
Date date = new Date(System.currentTimeMillis())
System.out.println(date.getTime())
}
}
实现思路:将两个时间转换为Timestamp类型(单位为毫秒),所以只需要计算出两个数值的差,之后直接将毫秒单位转换为秒,之后在转化为分钟就可以了:\x0d\x0aSimpleDateFormatsdf=newSimpleDateFormat("yyyy-MM-ddHH:mm:ss")\x0d\x0aDatestart=sdf.parse("2015-10-2205:12:10")\x0d\x0aDateend=sdf.parse("2013-10-2308:10:10")\x0d\x0a(end.getTime()-start.getTime())/(1000*60)\x0d\x0a知识普及:时间计算都是从1970年1月1日开始计算的。