Java operation time, reducing current time by one year, minus day, minus one months

Source: Internet
Author: User

When working with time in Java, you often encounter some values for a period of time, or calculate the number of days between periods

[Java]View PlainCopy
    1. Date date = new Date (); Get current time
    2. Calendar calendar = Calendar.getinstance ();
    3. Calendar.settime (date);
    4. Calendar.add (Calendar.year,-1); The current time minus one year, that is, one year ago
    5. Calendar.add (Calendar.month,-1); One months before the current time, that is, one months before the time
    6. Calendar.gettime (); //Get time a year ago, or one months ago

Please click---"Java Architect project, high concurrency cluster distributed, big Data high availability, video tutorial

Java operation time, reducing current time by one year, minus day, minus one months

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.