Modify the code to display the current date in the MM/DD/YYYYmode. And, display the number of hours, minutes, and seconds as well as the number of days left to the next New Year’s Day. An example of the needed output is shown in the attached picture (The values are just examples, they are not correct). Thank you. import java.util.Calendar; public class Sample
Modify the code to display the current date in the MM/DD/YYYYmode. And, display the number of hours, minutes, and seconds as well as the number of days left to the next New Year’s Day. An example of the needed output is shown in the attached picture (The values are just examples, they are not correct). Thank you.
import java.util.Calendar;
public class Sample
{
public static void main(String[] args)
{
Calendar cal = Calendar.getInstance();
int dayleft = findNewYearEve() - cal.get(Calendar.DAY_OF_YEAR);
String str = "There are " + dayleft + " days left to the next New Year's Day.";
System.out.println(str);
}
public static int findNewYearEve()
{
Calendar nyEve = Calendar.getInstance();
nyEve.set(nyEve.get(Calendar.YEAR), 11, 31);
//days left to next New Year
return (nyEve.get(Calendar.DAY_OF_YEAR) + 1);
}
}
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 2 images