DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Java: Format A Java Date From A String Using SimpleDateFormat

  • submit to reddit
        // Takes a string in MMDDYYYY format and parses it into a date

  String date = "07032008";
  //Set the SimpleDateFormat and then parse
  //Here M stands for month in year, d for date in month, and y for year
  //For a complete list of pattern letters visit <url></url>
  Date parsedDate = new SimpleDateFormat("MMddyyyy").parse(date);