Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I extract a datetime pattern from any string in Java?

Tags:

java

jodatime

How can I extract a datetime pattern from any string in Java?

The pattern is "YYYYMMddkm".

Are there any Joda time helper methods for this?

String 1: 2014041507393_somefile.somemore

String 2: _somefile2014041507393.somemore

like image 334
CodingHero Avatar asked Jul 14 '26 14:07

CodingHero


1 Answers

Use the following regular expression:

^\d{4}-\d{2}-\d{2}$

as in

String date = "2014041507393_somefile.somemore";

if (str.matches("\\d{4}-\\d{2}-\\d{2}")) {
    ...
}
like image 110
Rafa Romero Avatar answered Jul 16 '26 05:07

Rafa Romero



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!