Skip to content

Instantly share code, notes, and snippets.

@adojos
Last active March 9, 2023 11:02
Show Gist options
  • Save adojos/d7c0e97f1a25c2a02fffe368f125f9a8 to your computer and use it in GitHub Desktop.
Save adojos/d7c0e97f1a25c2a02fffe368f125f9a8 to your computer and use it in GitHub Desktop.
Java: Convert String to Date Using Calendar #java
private static void convertToCalendar() throws ParseException {
String strDate = "2015-06-12";
SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd");
Date date = dateFormatter.parse(strDate);
Calendar cal = Calendar.getInstance();
cal.setTime(date);
System.out.println(date);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment