How to Parse Dates from Strings

This example shows how to parse dates from strings using the SimpleDateFormat class.

The pattern is specified in the constructor, but could also be done with the applyPattern(String pattern) method.

This example should help ease the difficulty that all beginners seem to face when dealing with formatting dates in Java.



5 Replies to “How to Parse Dates from Strings”

  1. Don’t forget to call date.setLenient(false) before calling parse to have a strict matching.
    Without this, you can have strange result if your date string is a user input.

  2. Thats so true I recall the amount of time it took me to google out a good example of how to parse a string into date format some years back.

    There is a site nowadays called that provides some really nice examples of how to perform useful stuff in Java , its great time saver for beginners.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: