Display Date in 24-hour issue

android, android-date, datetime

Solution

So this post suggested to use SimpleDateFormat instead of DateFormat. For more explanation about the differences between these two classes, you could take a look at this post.

Problem

I am working simple app where I can get current `DateTime` and convert that into `24-hour` format. Code: ``` String DATE_yyyy_MM_dd_hh_mm_ss = "yyyy-MM-dd hh:mm:ss"; String DATE_yyyy_MM_dd_HH_mm_ss = "yyyy-MM-dd HH:mm:ss"; TextView tv=(TextView)findViewById(R.id.textView); tv.append("\n in 12-hour format: "+getDateFormatted(bootDate)); tv.append("\n in 24-hour format: "+getDateFormatted2(bootDate)); public String getDateFormatted(Date date){ return String.valueOf(DateFormat.format(DATE_yyyy_MM_dd_hh_mm_ss, date)); } public String getDateFormatted2(Date date){ return String.valueOf(DateFormat.format(DATE_yyyy_MM_dd_HH_mm_ss, date)); } ``` Problem: It's perfectly working in my devices `Samsung Galaxy S3(Android 4.3), S4(Android 4.3) and Nexus 5(Android 4.4)`. while the same code I am running in `Huawei Ascend Y330 device(Android 4.2.2)` it's not display properly. Screenshot in Samsung Galaxy S3, S4 and Nexus 5: Screenshot in Huawei Ascend Y330: So, what is the problem actually? I don't understand. Is it android system issue? or device issue? Any idea anyone.

Original source

Related problems