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

Method convertToDate

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

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)

Source from the content-addressed store, hash-verified

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);

Callers 9

sinceMethod · 0.95
getLastOnlineMethod · 0.95
getFirstOnlineMethod · 0.95
drawMethod · 0.95
drawScreenMethod · 0.95
callMethod · 0.95
initGuiMethod · 0.95
getDescriptionMethod · 0.95
parseTimeMethod · 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