Answer the question
In order to leave comments, you need to log in
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
str.replaceAll("^(\\d{4})-(\\d{2})-(\\d{2})$", "$3-$2-$1"));
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 questionAsk a Question
731 491 924 answers to any question