0

可能重复:
在java中计算日期/时间差

我为用户提供了使用日期选择器选择日期的选项。是否有任何内置方法可以用来计算用户选择日期和今天日期的持续时间(以天为单位)。

4

3 回答 3

2

我不喜欢回答这个问题,因为有数百万这样的问题(在发布问题之前使用搜索选项)。使用乔达时间。有一Period堂课,对你有用。

于 2012-09-18T13:10:11.457 回答
0
Date today = new Date(); // the date of today
Date target = new Date(); // the date of when the user picks

long todayEpoch = today.getTime(); // or can use = System.currentTimeMillis();
long targetEpoch = target.getTime();

long daysInMs = targetEpoch - todayEpoch; //days in MS's

//the # of days
float days = (daysInMs/1000/60/60/12);
于 2012-09-18T13:12:13.897 回答
0

以毫秒为单位获取两次之间的差异。你可以通过 Java 的 Calendar 类获得 Days。

于 2012-09-18T13:11:31.117 回答