In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
Editor to share with you how to use the calendar add method, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!
Because the project needs to count the log records of the specified date, the add method of Calendar is used to make relevant dynamic changes to the date parameters. But after reading the above introduction of javadoc, it is not very clear. I just said what add can do, but did not introduce how to implement it.
What does calendaradd do?
After reading some materials on the Internet, most of them are talking about the difference between add and roll. In fact, we only need to use the add method to solve most of the functions. For example, if we need to get the time before or after the current year, month, day, hour, minute, second, millisecond, how to use the add method? At first, I didn't know. I asked the technical director and he gave me a piece of code to try it out by myself.
The calendaradd code is as follows:
PublicstaticDateaddYears (Datedate,intamount)
{
Returnadd (date,1,amount)
}
PublicstaticDateaddMonths (Datedate,intamount)
{
Returnadd (date,2,amount)
}
PublicstaticDateaddWeeks (Datedate,intamount)
{
Returnadd (date,3,amount)
}
PublicstaticDateaddDays (Datedate,intamount)
{
Returnadd (date,5,amount)
}
PublicstaticDateaddHours (Datedate,intamount)
{
Returnadd (date,11,amount)
}
PublicstaticDateaddMinutes (Datedate,intamount)
{
Returnadd (date,12,amount)
}
PublicstaticDateaddSeconds (Datedate,intamount)
{
Returnadd (date,13,amount)
}
}
Tested in a test class, if 1 represents an operation on the year, 2 on the month, 3 on the week, 5 on the date, 11 on the hour, 12 on the minute, 13 on the second, and 14 on the millisecond.
The above is all the content of this article "how to use the calendar add method". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.