MCPcopy Create free account
hub / github.com/5zig/The-5zig-Mod / convertToDateWithoutTime

Method convertToDateWithoutTime

Utils/src/eu/the5zig/util/Utils.java:286–302  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.

Callers 1

drawMethod · 0.95

Calls 5

setTimeMethod · 0.80
formatMethod · 0.80
getMethod · 0.65
getInstanceMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected