I'm going to assume that getCurrentUrl() returns the full url not just the query string.
At a high level I see the process as
- Url decode the string
- Parse the query string into a map
- Transform the datepicker value from mm-dd-yyyy to yyyy-mm-dd which is just iso8601
Steps 1 and 2 can be done with a library such as OkHttp
final HttpUrl currentUrl = HttpUrl.parse(driver.getCurrentUrl());
if (currentUrl != null) {
final String inputDate = currentUrl.queryParameter("datepicker");
}
If you don't want to use a/that library there are some zero dependency options in this other question.
Step 3 has some options depending how robust you need this.
- Direct string manipulation.
- Use a library or built in date utility.
If this doesn't matter much the string manipulation would be the simplest. Just create a new string with the yyyy, a '-', and the mm-dd.
The downside is that it doesn't offer any way to validate the date.
Here is a library option
SimpleDateFormat parseFormatter = new SimpleDateFormat("dd-MM-yyyy");
Date date = parseFormatter.parse(inputDate);
SimpleDateFormat outputFormatter = new SimpleDateFormat("yyyy-MM-dd");
String date = outputFormatter.format(date);
System.out.println(date);
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…