Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,859 questions

51,780 answers

573 users

How to calculate the date six months from the current date in Java

1 Answer

0 votes
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

public class FutureDateCalculator {
    // Function to calculate future date by adding given months
    public static LocalDate calculateFutureDate(int monthsToAdd) {
        return LocalDate.now().plusMonths(monthsToAdd);
    }

    public static void main(String[] args) {
        LocalDate futureDate = calculateFutureDate(6);
        
        // Define the date format
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");

        // Print the new date
        System.out.println("Date six months from now: " + futureDate.format(formatter));
    }
}


 
/*
run:
 
Date six months from now: 2025-12-11
 
*/

 



answered Jun 11, 2025 by avibootz

Related questions

...