M
M
Maks Burkov2017-04-01 12:01:54
Java
Maks Burkov, 2017-04-01 12:01:54

Regular for the date, how to write this?

I can not find a suitable regular expression for the date.
For this format :
2012-12-12 and vice versa 12-12-2012 and also for 01-12-2012 , 01-01-2012 and vice versa
2012-01-12 , 2012-01-01 .
Is there any resource on the net for generating regular expressions?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vitaliy Orlov, 2017-04-01
@Maks00088

str.replaceAll("^(\\d{4})-(\\d{2})-(\\d{2})$", "$3-$2-$1"));

and vice versa
If the date is always a standard date, then it's better to use this
https://docs.oracle.com/javase/7/docs/api/java/tex...
String input = "Thu Jun 18 20:56:02 EDT 2009";
        SimpleDateFormat parser = new SimpleDateFormat("EEE MMM d HH:mm:ss zzz yyyy");
        Date date = parser.parse(input);
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
        String formattedDate = formatter.format(date);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question