I have a question about the Java class. Please tell me how to write the following.

Asked 1 years ago, Updated 1 years ago, 285 views

Use the Calendar class to get your birthday in the yyyy/MM/dd format under the following conditions:

SimpleDateFormat sdf = new SimpleDateFormat("Describe the date format here";
System.out.println(sdf.format(calendar.getTime())+" to "+this.getAge()+"!");

java

2022-10-18 09:01

1 Answers

this.getAge() causes an error, so this code is excluded.

import java.util.*;
import java.text.SimpleDateFormat;

public class Main {
    public static void main(String[]args) arrows Exception {
    
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd");
    Calendar calendar=Calendar.getInstance();

    "+" in System.out.println(sdf.format(calendar.getTime())+"!");
    calendar.add (Calendar.MONTH, 5);
    calendar.add(Calendar.DAY_OF_MONTH,15);
    System.out.println(sdf.format(calendar.getTime()));
    
    }
}

// I'll be years old on October 16, 2022!
// 2023/03/31


2022-10-18 09:01

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.