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

06.18.2008
| 15206 views |
  • 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>http://java.sun.com/javase/6/docs/api/java/text/SimpleDateFormat.html</url>
  Date parsedDate = new SimpleDateFormat("MMddyyyy").parse(date);