Detailed explanation of calendar class usage examples in Java

This article describes the usage of calendar class in Java. Share with you for your reference, as follows:

Calendar in Java is often ignored in development. This blog summarizes this class, which is helpful for later projects.

Function of calendar constant (field)

Summary:

1) The real meaning of constants is as above. We generally use these constants for assignment. In other words, we can obtain values through them, and we can also use them for corresponding assignment. 2) when assigning values, it is worth noting that week and month need to specify setfirstdayofweek. However, month needs to add or subtract 1. 3) when assigning values, We usually use calendar YEAR、Calendar. MONTH 、Calendar. DAY_ OF_ MONTH、 Calendar. HOUR_ OF_ DAY 、Calendar. MINUTE、 Calendar. SECOND

Main assignment statement

Main calculation

Summary:

1) About the calculation of roll, Cal roll(Calendar.DAY_OF_MONTH,32); Although 32 has exceeded the maximum possible 31, Cal will not exceed the month, but recalculate the remaining days after subtracting 32 from the days of the month; 2) For the calculation of add, cal1 add(Calendar.MONTH,1); If the current is 8-31, then, add a month, it is 9-30. This is the real accuracy

Main value statement

Summary:

1) Obtaining the maximum value and the minimum value is a very common method. 2) after obtaining the number of milliseconds, it can be calculated through 1000 * 60 * 60

Calendar gets the current day \ current month \ current week

PS: here are some online tools about date and day calculation for you to use:

Online date / day Calculator: http://tools.jb51.net/jisuanqi/date_jisuanqi

Online perpetual calendar: http://tools.jb51.net/bianmin/wannianli

Online lunar / Gregorian calendar conversion tool: http://tools.jb51.net/bianmin/yinli2yangli

Readers interested in more Java related content can view the special topics of this site: summary of Java date and time operation skills, tutorial on Java data structure and algorithm, summary of Java DOM node operation skills and summary of Java cache operation skills

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