|
16 | 16 | import android.text.StaticLayout;
|
17 | 17 | import android.text.TextPaint;
|
18 | 18 | import android.text.TextUtils;
|
| 19 | +import android.text.format.DateFormat; |
19 | 20 | import android.text.style.StyleSpan;
|
20 | 21 | import android.util.AttributeSet;
|
21 | 22 | import android.util.TypedValue;
|
|
34 | 35 | import java.util.Collections;
|
35 | 36 | import java.util.Comparator;
|
36 | 37 | import java.util.List;
|
| 38 | +import java.util.Locale; |
37 | 39 |
|
38 | 40 | /**
|
39 | 41 | * Created by Raquib-ul-Alam Kanak on 7/21/2014.
|
@@ -1115,25 +1117,28 @@ public DateTimeInterpreter getDateTimeInterpreter() {
|
1115 | 1117 | mDateTimeInterpreter = new DateTimeInterpreter() {
|
1116 | 1118 | @Override
|
1117 | 1119 | public String interpretDate(Calendar date) {
|
1118 |
| - SimpleDateFormat sdf; |
1119 |
| - sdf = mDayNameLength == LENGTH_SHORT ? new SimpleDateFormat("EEEEE") : new SimpleDateFormat("EEE"); |
1120 |
| - try{ |
1121 |
| - String dayName = sdf.format(date.getTime()).toUpperCase(); |
1122 |
| - return String.format("%s %d/%02d", dayName, date.get(Calendar.MONTH) + 1, date.get(Calendar.DAY_OF_MONTH)); |
1123 |
| - }catch (Exception e){ |
| 1120 | + try { |
| 1121 | + SimpleDateFormat sdf = mDayNameLength == LENGTH_SHORT ? new SimpleDateFormat("EEEEE M/dd", Locale.getDefault()) : new SimpleDateFormat("EEE M/dd", Locale.getDefault()); |
| 1122 | + return sdf.format(date.getTime()).toUpperCase(); |
| 1123 | + } catch (Exception e) { |
1124 | 1124 | e.printStackTrace();
|
1125 | 1125 | return "";
|
1126 | 1126 | }
|
1127 | 1127 | }
|
1128 | 1128 |
|
1129 | 1129 | @Override
|
1130 | 1130 | public String interpretTime(int hour) {
|
1131 |
| - String amPm; |
1132 |
| - if (hour >= 0 && hour < 12) amPm = "AM"; |
1133 |
| - else amPm = "PM"; |
1134 |
| - if (hour == 0) hour = 12; |
1135 |
| - if (hour > 12) hour -= 12; |
1136 |
| - return String.format("%02d %s", hour, amPm); |
| 1131 | + Calendar calendar = Calendar.getInstance(); |
| 1132 | + calendar.set(Calendar.HOUR_OF_DAY, hour); |
| 1133 | + calendar.set(Calendar.MINUTE, 0); |
| 1134 | + |
| 1135 | + try { |
| 1136 | + SimpleDateFormat sdf = DateFormat.is24HourFormat(getContext()) ? new SimpleDateFormat("HH:mm", Locale.getDefault()) : new SimpleDateFormat("hh a", Locale.getDefault()); |
| 1137 | + return sdf.format(calendar.getTime()); |
| 1138 | + } catch (Exception e) { |
| 1139 | + e.printStackTrace(); |
| 1140 | + return ""; |
| 1141 | + } |
1137 | 1142 | }
|
1138 | 1143 | };
|
1139 | 1144 | }
|
|
0 commit comments