Formats a String by date. @param millis Time in milliseconds. @return either 'Today' or 'Yesterday' or the Date and time in local Format.
(long millis)
| 284 | * @return either 'Today' or 'Yesterday' or the Date and time in local Format. |
| 285 | */ |
| 286 | public static String convertToDateWithoutTime(long millis) { |
| 287 | Date dateTime = new Date(millis); |
| 288 | Calendar calendar = Calendar.getInstance(); |
| 289 | calendar.setTime(dateTime); |
| 290 | Calendar today = Calendar.getInstance(); |
| 291 | Calendar yesterday = Calendar.getInstance(); |
| 292 | yesterday.add(Calendar.DATE, -1); |
| 293 | |
| 294 | if (calendar.get(Calendar.YEAR) == today.get(Calendar.YEAR) && calendar.get(Calendar.DAY_OF_YEAR) == today.get(Calendar.DAY_OF_YEAR)) { |
| 295 | return "Today"; |
| 296 | } else if (calendar.get(Calendar.YEAR) == yesterday.get(Calendar.YEAR) && calendar.get(Calendar.DAY_OF_YEAR) == yesterday.get(Calendar.DAY_OF_YEAR)) { |
| 297 | return "Yesterday"; |
| 298 | } else { |
| 299 | DateFormat timeFormatter = DateFormat.getDateInstance(DateFormat.SHORT); |
| 300 | return timeFormatter.format(dateTime); |
| 301 | } |
| 302 | } |
| 303 | |
| 304 | /** |
| 305 | * Checks if both times are still the same day. |