Detailed explanation of java time and date use and query code
As long as the format is correct, you can directly compare strings, and the same is true for strings accurate to seconds
Calculate date difference
Time and date classes are often used, so the commonly used date methods and attributes are summarized as follows to facilitate you to find @ H_ 404_ 13@
1. Calculate the maximum number of days in a month
Note: you'd better clear before using the set method, otherwise a lot of information will be inherited from the current system time @ H_ 404_ 13@
2. Conversion of calendar and date @ h_ 404_ 13@
(1) Convert calendar to date
(2) Convert date to calendar
3. Format output date and time
4. Calculate the week of the year @ h_ 404_ 13@
(1) Calculate which week of the year a day is
(2) Calculate the day of the week in a year
Output:
5. Usage of add() and roll() @ h_ 404_ 13 @ (1) add() method
Output: @ h_ 404_ 13@ 2006-08-30 @H_ 404_ 13@ 2006-10-03 @H_ 404_ 13@
(2) Roll method
Output:
2006-10-29
2006-10-03
It can be seen that the roll () method circulates within this month. Generally, the add () method is used;
6. Calculate the number of days between two arbitrary times
(1) Pass in calendar object
(2) Pass in Date object
Similarly, you can use the same method to calculate the hours, minutes, seconds, etc. @ h between any two times_ 404_ 13 @ note: the above methods are calculated based on time, and sometimes they are not satisfactory, such as:
The calculation result is 0, but we may let the calculation result become 1. At this time, we can use the following method: @ h_ 404_ 13 @ set the time of endday before transferring parameters, such as:
In this way, it is transmitted to start day and end day, and the result is as we want. However, if the above methods are troublesome, you can refer to the following methods: @ h_ 404_ 13 @ (3) improve the method of accurately calculating the interval days
Get current system time:
In the development of web applications, we need to do different transformations for different database date types in our program. If the corresponding database data is of Oracle date type, that is, only the date of month, year and day are required, you can choose to use Java sql. Date type. If it corresponds to the datetime type of MSSqlServer database, that is, it requires year, month, day, hour, minute and second, select Java sql. Timestamp type
You can use dateformat to define the format of time and date. Just turn a string
Here is an example:
Java code
summary
The above is all about the detailed explanation of java time and date use and query code in this article. I hope it will be helpful to you. Interested friends can continue to refer to other related topics on this site. If there are deficiencies, please leave a message to point out. Thank you for your support!