Use calendar in Java to calculate the number of days and weeks between two dates

preface

What exactly is a calendar? The Chinese translation is the calendar, then we can immediately think that there are Yang (public) calendar and Yin (agricultural) calendar in our life. What's the difference between them?

For example:

Definition of month - Yang ` (public) calendar has 12 months in a year, and the days of each month are different; Lunar (agricultural) calendar, fixed for 28 days per month

The first day of the week - Sun (public) calendar Sunday is the first day; Monday is the first day in the lunar calendar

In fact, there are many methods in history. Their differences are too great. For example, if a person's birthday is "August 8", it may be August 8 of the Yang (male) calendar, but it can also be the date of the Yin (agricultural) calendar. Therefore, in order to unify timing, you must specify a calendar selection. Now the most popular and universal calendar is "Gregorian calendar". That is, when we talk about the year, we often use "what year of A. D.". The calendar abstract class defines enough methods to express the rules of the calendar. Java itself provides an implementation of the "Gregorian calendar" rule. We're from calendar The instance obtained in getInstance () is a "gregoriancalendar" object (consistent with the result you obtained through new gregoriancalendar()). I won't say much below. Let's take a look at the body of this article.

Use the calendar class in Java to calculate the number of days and weeks between two dates!

Calculate the number of days between dates:

Calculate the number of weeks:

summary

The above is all about using the calendar in Java to calculate the days and weeks between two dates. I hope the content of this article can bring some help to your study or work. If you have any questions, you can leave a message.

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
分享
二维码
< <上一篇
下一篇>>