I have an iOS/Android app sending data to the Python backend.
In both apps, the user selects a date and time from a picker, and it is sent to the server:
Android:
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
String formattedDate = simpleDateFormat.format(date);
URL url = new URL("https://example.com/api/test?distance=" + distance + "&date=" + formattedDate);
iOS:
let formatter = DateFormatter()
formatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"
let formattedDate = formatter.string(from: date)
let url = URL(string: "https://example.com/api/test?distance=(distance)&date=(formattedDate)")!
On the server, this is interpreted as follows:
date = request.GET.get('date', None)
if date:
journey_date = datetime.fromisoformat(date)
I’ve just had a weird error come through, where the server is receiving the date in an unexpected format:
ValueError at /api/test/
Invalid isoformat string: '2024-05-20T3:38:12.711u202fPMZ'
Basically the time looks like it is AM/PM format, rather than 24 hour.
In all the testing I’ve done so far, I’ve never come across this. Assuming the user has not sent a manual request to the endpoint (e.g. via Postman), and that they have just used the app UI, how might the date be received in this format when the specified format was yyyy-MM-dd'T'HH:mm:ss.SSS'Z'
?