I want to have a program that asks the user for an input of either yes or no. if no, it does nothing, but if it is a yes, it will run the following code.
import java.util.Date;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
public class GettingCurrentDate {
public static void main(String[] args) {
//getting current date and time using Date class
DateFormat df = new SimpleDateFormat("dd/MM/yy HH:mm:ss");
Date dateobj = new Date();
System.out.println(df.format(dateobj));
/*
* getting current date time using calendar class
*
* An Alternative of above
*/
Calendar calobj = Calendar.getInstance();
System.out.println(df.format(calobj.getTime()));
}
}