Say I have a url:
https://example/dateParam/
and I have a date value (ZULU format) entered by the user such as:
2016-07-20 13:10:04 +0300.
I want the result to be a properly encoded URL:
https://example/dateParam/2016-07-20%2013%3A10%3A04%20%2B0300
When I tried to do:
String dateParam = "2016-07-20 13:10:04 +0300";
String encodedParam = URLEncoder.encode(dateParam, "UTF-8");
System.out.println(encodedParam);
I get the following result:
2016-07-20+13%3A10%3A04+%2B0300
For the spaces I need %20 insteadof +. What's the best way to achieve this? I tried URLEncoder and creating URI/URL objects but none of them come out quite right.