Code example for TimeUnit

Methods: toDaystoHourstoMillistoMinutes

0
			e.printStackTrace();
		} 
		Date now = new Date();
 
		String ago = TimeUnit.MILLISECONDS.toMillis(now.getTime()
				- past.getTime())
				+ " milliseconds ago"; 
		if (TimeUnit.MILLISECONDS.toMinutes(now.getTime() - past.getTime()) > 0)
			ago = TimeUnit.MILLISECONDS.toMinutes(now.getTime()
					- past.getTime())
					+ " minutes ago"; 
		if (TimeUnit.MILLISECONDS.toHours(now.getTime() - past.getTime()) > 0)
			ago = TimeUnit.MILLISECONDS.toHours(now.getTime() - past.getTime())
					+ " hours ago"; 
		if (TimeUnit.MILLISECONDS.toDays(now.getTime() - past.getTime()) > 0)
			ago = TimeUnit.MILLISECONDS.toDays(now.getTime() - past.getTime())
					+ " days ago"; 
 
		return ago;
	} 
 
Experience pair programming with AI  Get Codota for Java