im a beginner in Java and I need the user to input a year month and day and then put it in the form of yyyy-mm-dd using the Date class but I keep getting the "week day, month, date, time, year"
this is part of the code

Scanner input = new Scanner(System.in);
PrintStream output = System.out;

output.println("Birth Year:");
int birthYear = input.nextInt();

output.println("Birth Month:");
int birthMonth = input.nextInt();

output.println("Birth Day:");
int birthDay = input.nextInt();

Date dateOfBirth = new Date(birthYear,birthMonth,birthDay);
System.out.println(dateOfBirth);

i need to print out the date the user put in can someone help me with this class please?

Recommended Answers

All 3 Replies

the thing is that i must use Date for this assignment
if someone can give me an example please how to use Date and get a yyyy-mm-dd date format that would be great
thanks

the thing is that i must use Date for this assignment
if someone can give me an example please how to use Date and get a yyyy-mm-dd date format that would be great
thanks

Using the information readily available at the website I supplied for you:

Date currentDate = new Date();
         SimpleDateFormat amazinglySimpleDateFormat = new SimpleDateFormat("yyyy-mm-dd");
         String omgAFormattedDate = amazinglySimpleDateFormat.format(currentDate);
         System.out.println(omgAFormattedDate);
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.