The example in this article mainly calculates the difference between the month of two dates, as follows:
package com.forezp.util;import org.joda.time.DateTime;import org.joda.time.Months;import org.joda.time.format.DateTimeFormat;import org.joda.time.format.DateTimeFormat;/** * In JAVA, how to calculate the month difference between two dates? <br> * * * @author Administrator * */public class Demo1 {public static void main(String[] args) {DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyy-MM-dd");DateTime start = formatter.parseDateTime("2017-07-11");DateTime end = formatter.parseDateTime("2017-11-19");int months = Months.monthsBetween(start, end).getMonths();System.out.println(months);}}Running results:
Maven import dependencies:
<dependency> <groupId>joda-time</groupId> <artifactId>joda-time</artifactId> <version>2.9.6</version></dependency>
Summarize
The above is the entire content of this article about Java programming implementation to calculate the month difference instance code for two dates. I hope it will be helpful to everyone. Interested friends can continue to refer to other related topics on this site. If there are any shortcomings, please leave a message to point it out. Thank you friends for your support for this site!