Formats a String by time. @param millis Time in milliseconds. @return either 'Today' or 'Yesterday' and time in HH:MM-Format or the Date and time in local Format.
(long millis)
| 251 | * @return either 'Today' or 'Yesterday' and time in HH:MM-Format or the Date and time in local Format. |
| 252 | */ |
| 253 | public static String convertToDate(long millis) { |
| 254 | Date dateTime = new Date(millis); |
| 255 | Calendar calendar = Calendar.getInstance(); |
| 256 | calendar.setTime(dateTime); |
| 257 | Calendar today = Calendar.getInstance(); |
| 258 | Calendar yesterday = Calendar.getInstance(); |
| 259 | yesterday.add(Calendar.DATE, -1); |
| 260 | DateFormat timeFormatter = DateFormat.getTimeInstance(DateFormat.SHORT); |
| 261 | |
| 262 | if (calendar.get(Calendar.YEAR) == today.get(Calendar.YEAR) && calendar.get(Calendar.DAY_OF_YEAR) == today.get(Calendar.DAY_OF_YEAR)) { |
| 263 | return "Today " + timeFormatter.format(dateTime); |
| 264 | } else if (calendar.get(Calendar.YEAR) == yesterday.get(Calendar.YEAR) && calendar.get(Calendar.DAY_OF_YEAR) == yesterday.get(Calendar.DAY_OF_YEAR)) { |
| 265 | return "Yesterday " + timeFormatter.format(dateTime); |
| 266 | } else { |
| 267 | timeFormatter = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT); |
| 268 | return timeFormatter.format(dateTime); |
| 269 | } |
| 270 | } |
| 271 | |
| 272 | public static String convertToDateAndTime(long millis) { |
| 273 | Date dateTime = new Date(millis); |
no test coverage detected