Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我需要使用 java.util.Date、java.util.Calendar 和 java.text.SimpleDateFormat 计算两个日期之间经过的天数。我脑子坏了,我怎么能做到这一点?
这似乎是一个面试问题,在两个月前的一次面试中向我提出了类似的问题。
好吧,这里有另一个提示:你有两个约会。Java 为您提供每个日期的毫秒时间。说 t1 和 t2。
不失一般性,我们可以假设 t1>t2。现在 t = t1-t2
将 t 除以 86400 * 1000 (一天中的毫秒数),这就是你的答案:)