0

In my Android project, I have 3 variables (string) :

String day = "26";
String month = "03";
String year = "1989";

I would like to have a variable (String date) with the date format of the device (depending of the langage) like this :

  • If the device is in french, date = "26/03/1989"
  • If the device is in english (USA), date = "03/26/1989"
  • etc

How can I do that ?

Thanks

Jéwôm'
  • 3,753
  • 5
  • 40
  • 73

2 Answers2

1

Join your strings into one like in this example (obviously you can omit the date)

    String dateString = "03/26/2012 11:49:00 AM";
    SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy hh:mm:ss aa");
    Date convertedDate = new Date();
    try {
        convertedDate = dateFormat.parse(dateString);
    } catch (ParseException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    System.out.println(convertedDate);

Prints:

Mon Mar 26 11:49:00 EEST 2012

EDIT: This example doesn't show how to get the phone local date format

Lorenzo Vincenzi
  • 1,153
  • 1
  • 9
  • 26
0

SimpleDateFormat already support that.

You can especify your desired Locale or get the default from the device.

Take a look at the docs.

Hope this helps.

Nanoc
  • 2,381
  • 1
  • 20
  • 35