1

I'm working on a java project and I need to send a date format within a URL but the container of date send it with spaces which is impossible so i convert it to a string and I used the replace method to replace the spaces with "" or "-" but it didn't work

Here is the code:

Date date = date_debut.getDate();
String dateconver= date.toString();
String datef= dateconver.replace(" ", "");

And here is the error: incompatible types string can not be converted to char

I have tried also to use replaceAll but the IDE didn't even show it

2

1 Answer 1

2

Try this code

Date date = date_debut.getDate();
String dateconver= date.toString();
String datef= dateconver.replaceAll("\\s", "");
Sign up to request clarification or add additional context in comments.

8 Comments

nop error illegal character \
add Log.d("Test","String: " + dateconver); after date.toString(); and paste the Logcat error
this will remove \s occurrences (not whitespaces). To regex-based replace, use .replaceAll(). Can't understand why this answer is upvoted, as even if properly used it will produce some wierd MonMar2814:43:56AST2016
Bad copy paste from duplicate question.
incompatible types !!!! that's really weird many people used the same code and it worked , for me it didn't
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.