Java programming to calculate the code of the Two-date month difference instance, java instance
This example mainly calculates the month difference between two dates, as shown in the following code:
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. dateTimeFormatter;/*** in JAVA, how do I 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 result:
Maven import dependency:
<dependency> <groupId>joda-time</groupId> <artifactId>joda-time</artifactId> <version>2.9.6</version></dependency>
Summary
The above is all about the Java programming implementation of the month difference instance code for two dates, I hope to help you. If you are interested, you can continue to refer to other related topics on this site. If you have any shortcomings, please leave a message. Thank you for your support!