本文实例讲述了android获取时间差的方法。分享给大家供大家参考。具体分析如下:

有些时候我们需要获取当前时间和某个时间之间的时间差,这时如何获取呢?

1. 引用如下命名空间:

import java.util.Date;
import android.text.format.DateFormat;

2. 设置时间格式:

SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

3. 获取时间:

Date curDate = new Date(System.currentTimeMillis());
//PROCESSING
Date endDate = new Date(System.currentTimeMillis());
long diff = endDate.getTime() - curDate.getTime();

这样获取的就是时间间隔了,并且是ms级别的。

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-06-14
  • 2021-12-27
  • 2022-12-23
  • 2021-07-10
  • 2022-12-23
猜你喜欢
  • 2021-09-12
  • 2021-05-26
  • 2021-11-30
  • 2022-12-23
  • 2021-12-27
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案