Java get time difference (days difference, small time difference, minute difference) code example

There are many blog posts on the Internet about how to get the time difference. I have a look. Most of them are implemented by using the calendar class, but they are all confused. Here I use simpledateformat. It is relatively simple and I think it is more suitable for use.

Simpledateformat is a concrete class that formats and analyzes data in a country sensitive manner. It allows formatting (date - > text), parsing (text - > date), and standardization. Simpledateformat allows you to select any user specified way to start for date time formatting. However, you want to create a date time formatter with gettimeinstance, getdateinstance, or getdatetimeinstance in dateformat. Each class method returns a date / time formatter initialized in the default format. You can use the applypattern method to modify the formatting method as needed.

First, we initialize our simpledateformat

1. Calculate the difference of days.

2. Calculate small time difference

3. Calculate the minute difference:

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>