I am formatting dates like this:
public static String toFormattedDate(@NonNull Time time, String toFormat) {
mDateFormat = new SimpleDateFormat(toFormat);
Date date = new Date();
date.setTime(time.toMillis(true));
return mDateFormat.format(date);
}
and the format I am using is:
public static final String TIME = "hh:mm a";
But it differs between the two devices that I am using for testing...
Nexus 10:
Nexus 5X:
How can I format it uniformly between devices?
You may either have to use either the 24 hour value to determine what to append so that you can add the format you desire.
public static final String TIME = "hh:mm";
and then
String ampm = Integer.parseInt(time.valueOf("hh")) >= 12 ? "PM" : "AM";
...
return mDateFormat.format(date)+" "+ampm;
Or if you feel lazy you can just do without changing the value of TIME:
return mDateFormat.format(date).toUpperCase().replace(".","");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With