Code example for Date

Methods: getDate

0
	} 
	 
	@SuppressWarnings("deprecation") 
	public static String formatDate(long timestamp) {
		Date curDate = new Date(System.currentTimeMillis());
		Date date = new Date(timestamp);
		if (curDate.getDate() == date.getDate()) {
			SimpleDateFormat format = new SimpleDateFormat("今天 HH:mm:ss");
			return format.format(date);
		} else if (curDate.getDate() == date.getDate() + 1) {
			SimpleDateFormat format = new SimpleDateFormat("昨天 HH:mm:ss");
			return format.format(date);
		} else if (curDate.getDate() == date.getDate() + 2) {
			SimpleDateFormat format = new SimpleDateFormat("前天 HH:mm:ss");
			return format.format(date);
		} else { 
			SimpleDateFormat format = new SimpleDateFormat(
					"yyyy-MM-dd HH:mm:ss"); 
			return format.format(date);
		} 
	}