A PHP Error was encountered

Severity: 8192

Message: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated

Filename: libraries/Filtered_db.php

Line Number: 23

Java program to subtract days from the current date
Q:

Java program to subtract days from the current date

0

Java program to subtract days from the current date

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Program/Source Code:

The source code to subtract days from the current date is given below. The given program is compiled and executed successfully.

// Java program to subtract days from 
// the current date

import java.util.*;

public class Main {
  public static void main(String[] args) {
    Calendar cal = Calendar.getInstance();

    cal.add(Calendar.DATE, -12);
    System.out.println("Date before 12 days: " + cal.getTime());
  }
}

Output:

Date before 12 days: Mon Mar 21 05:37:24 GMT 2022

Explanation:

In the above program, we created a class Main that contains a static method main(). The main() method is the entry point for the program, here we created the object of the Calendar class and subtracted the 12 days from the current date using add() method, and printed the result.

 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now