forked from builder-of-web3/HackR_Java_Code
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreformatting dates
More file actions
27 lines (19 loc) · 820 Bytes
/
reformatting dates
File metadata and controls
27 lines (19 loc) · 820 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
public static List<String> reformatDate(List<String> dates){
// Write your code here
List<String> result = new ArrayList();
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("d MMMM yyyy");
SimpleDateFormat finalDateFormat = new SimpleDateFormat("yyyy-MM-dd");
for(int i = 0; i < dates.size(); i++) {
String string = dates.get(i);
string = string.replaceFirst("[a-zA-Z]{2}", "");
try {
Date tempFormattedDate = simpleDateFormat.parse(string);
String finalFormattedDate = finalDateFormat.format(tempFormattedDate);
result.add(finalFormattedDate);
} catch(ParseException pe) {
pe.printStackTrace();
}
}
return result;
}
}