-1

In my android application I was sending a date in the format 05/03/2017 in a web service to get response. Now if I change my phone's language to Arabic the date is being sent in Arabic. So how should I convert a date in Arabic to a format like 05/03/2017 ?

Shubham Raitka
  • 1,034
  • 8
  • 15

3 Answers3

6

Thanks for the answers, but I have got the solution.

I have a string variable currentFormattedDate which has date in Arabic. Now I had to convert this to MM/dd/yyyy in English before sending it in Web Service.

So this is what I did:-

SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");
Date date = sdf.parse(currentFormattedDate);
SimpleDateFormat finalDateFormat = new SimpleDateFormat("MM/dd/yyyy",Locale.US);
finalDate = finalDateFormat.format(date);

I first converted the Arabic string date to Date object, then converted it to the format I need with Locale as US,as I need in English. Now I passed this finalDate and got the correct response.

Shubham Raitka
  • 1,034
  • 8
  • 15
0

Use Locale.ROOT when you create the arguments for an API call. For example,

new SimpleDateFormat("dd/MM/yyyy", Locale.ROOT)
Joni
  • 108,737
  • 14
  • 143
  • 193
0

The Message you send should be the format of String,right? So, it won't occur any problem whether you change your phone's language.

Hancock
  • 1
  • 1
  • 1
    Yes, but no data is returned by the server as they are not handling it. So I need to convert it into English format. – Shubham Raitka May 03 '17 at 07:00
  • So,I think, that could be the problem of the format you got different from the web needed, try to use "Locale.Root" or "Locale.getDefault()" as the param. – Hancock May 03 '17 at 07:27