0

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

irrelevent
  • 27
  • 1
  • 6

1 Answers1

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