0
I’m making a collaborative application for android, so I made a server in PHP, and send the data to this server.
For a certain query I need to pass a date, from a Date Picker, here is the code:
String myFormat = "dd-MM-yy"; //In which you need put here
SimpleDateFormat sdf = new SimpleDateFormat(myFormat, Locale.US);
et_data.setText(sdf.format(myCalendar.getTime()));
String data = sdf.format(myCalendar.getTime()) +"";
The date variable is passed to the server, but on the server it is not interpreting as text.
But if I set the date variable to:
String data = "12-02-2018";
Works normally. The value that arrives on the server is this same, and the type is also String.
Does anyone know what it can be?
I did not understand your problem, I tested your code and it is working, at least as I imagine it should, since it is not clear your problem: https://ideone.com/ntrhqD
– user28595
That’s right, to me the code seems right. When I receive it on the PHP server it does not interpret this -> (String data = sdf.format(myCalendar.getTime()) +"";), as a String.
– G. Trentini
So the problem is not on the java side.
– user28595
How are you receiving this on the server side in PHP ? How do you "upload" the information ?
– Isac
You said if you set the variable as
12-02-2018
works. But theSimpleDateFormat
that you created usesdd-MM-yy
, which only prints the year with two digits. Try switching todd-MM-yyyy
– hkotsubo
Another detail is that the method
format()
already returns aString
, and concatenate with theString
empty (the part at the end+""
) is redundant and can be removed. So it would be onlyString data = sdf.format(myCalendar.getTime());
– hkotsubo