Вопрос

    SimpleDateFormat formato =new SimpleDateFormat("HH:mm:ss");
    Calendar cal = Calendar.getInstance();
    String fecha11 = String.valueOf(formato.format(cal.getTime()));

    Locale locale = new Locale("es", "ES");
    SimpleDateFormat format = new SimpleDateFormat("HH:MM:ss", locale);
    String fecha22 = String.valueOf(format.format(cal.getTime()));

Results: 14:06:12 (same that hour in my device) 14:16:55 (with Locale("es", "ES"))

And yes, i am in Spain (Bcn) ¬¬' somebody would explain me why?? And next question, is it happen when i change Locale to others countries?

Thanks,

Àlex

Это было полезно?

Решение

In your second example: SimpleDateFormat format = new SimpleDateFormat("HH:MM:ss", locale);, you are using MM instead of mm, so it is the month number instead of the minutes that gets printed (is should be 05 for May though).

Другие советы

mm is minutes. MM is month

your second format is Hour:Month:Seconds

edited after assylias comment

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top