[Solved] How to Convert Date to Int? [closed]


String year1= String.valueOf (year);
String month1= String.valueOf(month);
String day1= String.valueOf(day);

must be changed to

String year1= String.valueOf (num1);
String month1= String.valueOf(num2);
String day1= String.valueOf(num3);

because these 3 variables only hold the values entered by the user.

Also, not sure why you need the hour, because you never get that as inout from the user. In your case, what you’ve done for all these is use the new Date() as such which is throwing the exception.

The max you can do with your hour field is this

String hour1 = DateFormat3.format(hour); // Use the current time's hour value as you don't get any from user.

Side Note:- You can use a single SimpleDateFormat, single Scanner, and a lot of other optimizations, but that comes later, after you fix your code and logic.

1

solved How to Convert Date to Int? [closed]