so i need to take an input from User in the format of "MM/DD/YYYY" and later read the day and month from the user input to use in some other calculations i tried using strings and Gregorian calendar but i have no idea how to do that
Asked
Active
Viewed 128 times
0
-
show your code and then we can go on from there. – Ousmane D. Apr 08 '17 at 22:47
-
i tried writing some but didn't go anywhere – irrelevent Apr 08 '17 at 22:48
-
i'm talking input in a string is there any way to parse to use it in calendar – irrelevent Apr 08 '17 at 22:49
-
Hint: `java.time.MonthDay.from( LocalDate.parse( … , DateTimeFormatter.ofPattern( … ) ) )` – Basil Bourque Apr 10 '17 at 18:45
1 Answers
0
Calendar cal = Calendar.getInstance();
SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy", Locale.ENGLISH);
cal.setTime(dateFormat.parse("12/23/2017"));
Now you can get all kind of metrics form the calendar easily.

Torge
- 2,174
- 1
- 23
- 33
-
If you can, do yourself the favour of skipping the old classes `Calendar` and `SimpleDateFormat` and using the new classes `LocalDate` and `DateTimeFormatter` introduced in Java 8. See [this answer to the linked question](http://stackoverflow.com/a/43301263/5772882). – Ole V.V. Apr 08 '17 at 23:45