|
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.
|
@@ -1121,25 +1123,28 @@ public DateTimeInterpreter getDateTimeInterpreter() {
|
1121 | 1123 | mDateTimeInterpreter = new DateTimeInterpreter() {
|
1122 | 1124 | @Override
|
1123 | 1125 | public String interpretDate(Calendar date) {
|
1124 |
| - SimpleDateFormat sdf; |
1125 |
| - sdf = mDayNameLength == LENGTH_SHORT ? new SimpleDateFormat("EEEEE") : new SimpleDateFormat("EEE"); |
1126 |
| - try{ |
1127 |
| - String dayName = sdf.format(date.getTime()).toUpperCase(); |
1128 |
| - return String.format("%s %d/%02d", dayName, date.get(Calendar.MONTH) + 1, date.get(Calendar.DAY_OF_MONTH)); |
1129 |
| - }catch (Exception e){ |
| 1126 | + try { |
| 1127 | + SimpleDateFormat sdf = mDayNameLength == LENGTH_SHORT ? new SimpleDateFormat("EEEEE M/dd", Locale.getDefault()) : new SimpleDateFormat("EEE M/dd", Locale.getDefault()); |
| 1128 | + return sdf.format(date.getTime()).toUpperCase(); |
| 1129 | + } catch (Exception e) { |
1130 | 1130 | e.printStackTrace();
|
1131 | 1131 | return "";
|
1132 | 1132 | }
|
1133 | 1133 | }
|
1134 | 1134 |
|
1135 | 1135 | @Override
|
1136 | 1136 | public String interpretTime(int hour) {
|
1137 |
| - String amPm; |
1138 |
| - if (hour >= 0 && hour < 12) amPm = "AM"; |
1139 |
| - else amPm = "PM"; |
1140 |
| - if (hour == 0) hour = 12; |
1141 |
| - if (hour > 12) hour -= 12; |
1142 |
| - return String.format("%02d %s", hour, amPm); |
| 1137 | + Calendar calendar = Calendar.getInstance(); |
| 1138 | + calendar.set(Calendar.HOUR_OF_DAY, hour); |
| 1139 | + calendar.set(Calendar.MINUTE, 0); |
| 1140 | + |
| 1141 | + try { |
| 1142 | + SimpleDateFormat sdf = DateFormat.is24HourFormat(getContext()) ? new SimpleDateFormat("HH:mm", Locale.getDefault()) : new SimpleDateFormat("hh a", Locale.getDefault()); |
| 1143 | + return sdf.format(calendar.getTime()); |
| 1144 | + } catch (Exception e) { |
| 1145 | + e.printStackTrace(); |
| 1146 | + return ""; |
| 1147 | + } |
1143 | 1148 | }
|
1144 | 1149 | };
|
1145 | 1150 | }
|
|
0 commit comments