Display the current date in the following format: "06 15 2018".
Requirements:
The date must contain the month, day, and year, separated by a space.
The month should match the current month.
The day should match the current day.
The year should match the current year.
The entire date should be displayed on a single line.
package com.codegym.task.task05.task0528;
/*
Display today's date
*/
public class Solution {
public static void main(String[] args) {
//write your code here
System.out.println(java.time.LocalDate.now());
}
}
Without fancy stuff (although it is cool), you can just use a System.out.print
However, it's not really practice. You can create a class called whatever you want, initialize month, day, and year, and then display them. If (too_hard==true) System.out.print ("4 27 2019");
We can also use SimpleDateFormat
Date date = new Date();
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("MM dd yyyy");
String d = simpleDateFormat.format(date);
System.out.println(d);
Re quoting Khurram (from Lahore) "Keep it simple!!!". Dates aren't introduced yet so why to bother yourself with them. Try something similar to this simple thing --- System.out.println("03 04 2019");
you can look this discussion... https://stackoverflow.com/questions/26717733/print-current-date-in-java
and then modify the date output format to MM dd yyyy
This website uses cookies to provide you with personalized service. By using this website, you agree to our use of cookies. If you require more details, please read our Terms and Policy.