Created
February 11, 2015 10:52
-
-
Save eagafonov/eb9b5c77800911b1c229 to your computer and use it in GitHub Desktop.
Parse date per format
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.text.SimpleDateFormat; | |
import java.util.Date; | |
import java.text.ParsePosition; | |
public class DateTimeTest { | |
public static void main(String[] args) { | |
// Create parser | |
SimpleDateFormat df = new SimpleDateFormat("yyyy-mm-dd"); | |
// Parse correct data | |
Date date = df.parse("2015-02-11", new ParsePosition(0)); | |
// put | |
System.out.println("Parsed date: " + date.toString()); | |
date = df.parse("2015-02.11", new ParsePosition(0)); | |
// date is null since string does not match the format string | |
System.out.println("Parsed date: " + date); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment