Last active
July 31, 2018 01:39
-
-
Save emschwar/63e99a2233dc63c379adfc61288b7ef0 to your computer and use it in GitHub Desktop.
Tests how to parse LocalDateTime with DateTimeFormatter
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.time.LocalDateTime; | |
import java.time.format.DateTimeFormatter; | |
public class DateTimeFormatterExample { | |
public static void main(String []args) { | |
DateTimeFormatter pattern = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSS"); | |
LocalDateTime time = LocalDateTime.parse("2018-07-30T18:15:34.823", pattern); | |
System.out.println("parsed time: " + time.toString()); | |
} | |
} |
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
parsed time: 2018-07-30T18:15:34.823 |
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
It matches |
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.util.regex.Matcher; | |
import java.util.regex.Pattern; | |
public class RegexpExample { | |
public static void main(String []args) { | |
String timeString = "2018-07-30T18:15:34.823"; | |
String pattern = "\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}.\\d{3}"; | |
Pattern r = Pattern.compile(pattern); | |
Matcher m = r.matcher(timeString); | |
if (m.matches()) { | |
System.out.println("It matches"); | |
} else { | |
System.out.println("It doesn't match"); | |
} | |
} | |
} |
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.util.regex.Matcher; | |
import java.util.regex.Pattern; | |
public class RegexpExampleWithDateTimeFormatterPattern { | |
public static void main(String []args) { | |
String timeString = "2018-07-30T18:15:34.823"; | |
String pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS"; | |
Pattern r = Pattern.compile(pattern); | |
Matcher m = r.matcher(timeString); | |
if (m.matches()) { | |
System.out.println("It matches"); | |
} else { | |
System.out.println("It doesn't match"); | |
} | |
} | |
} |
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
It doesn't match |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment