Android examples for java.util:Date
build Date String
//package com.java2s; import java.util.Calendar; import java.util.Locale; public class Main { public static String buildDateString(Calendar calendarDate) { //month+1, because Calendar is zero-based (eg january = 0 and not 1) if (isCurrentDay(calendarDate)) return "Heute"; else {/* ww w. j a va 2 s . co m*/ String result = Integer.toString(calendarDate .get(Calendar.DAY_OF_MONTH)) + "." + (Integer .toString(calendarDate.get(Calendar.MONTH) + 1) + "." + Integer.toString(calendarDate .get(Calendar.YEAR))); result = calendarDate.getDisplayName(Calendar.DAY_OF_WEEK, Calendar.SHORT, Locale.getDefault()) + " " + result; return result; } } public static String buildDateString(int[] calendar) { Calendar myCalendar = Calendar.getInstance(); myCalendar.set(calendar[2], calendar[1], calendar[0]); //month+1, because Calendar is zero-based (eg january = 0 and not 1) if (isCurrentDay(calendar)) return "Heute"; else { String result = Integer.toString(myCalendar .get(Calendar.DAY_OF_MONTH)) + "." + (Integer.toString(myCalendar.get(Calendar.MONTH) + 1) + "." + Integer.toString(myCalendar .get(Calendar.YEAR))); result = myCalendar.getDisplayName(Calendar.DAY_OF_WEEK, Calendar.SHORT, Locale.getDefault()) + " " + result; return result; } } public static boolean isCurrentDay(int[] date) { Calendar currentCal = Calendar.getInstance(); if (date[0] == currentCal.get(Calendar.DAY_OF_MONTH) && date[1] == currentCal.get(Calendar.MONTH) && date[2] == currentCal.get(Calendar.YEAR)) return true; else return false; } public static boolean isCurrentDay(Calendar calendarDate) { Calendar currentDate = Calendar.getInstance(); return isSameDay(currentDate, calendarDate); } public static boolean isSameDay(Calendar calendarDate1, Calendar calendarDate2) { if (calendarDate1.get(Calendar.YEAR) == calendarDate2 .get(Calendar.YEAR) && calendarDate1.get(Calendar.MONTH) == calendarDate2 .get(Calendar.MONTH) && calendarDate1.get(Calendar.DAY_OF_MONTH) == calendarDate2 .get(Calendar.DAY_OF_MONTH)) return true; else return false; } public static boolean isSameDay(int[] date1, int[] date2) { if (date1[0] == date2[0] && date1[1] == date2[1] && date1[2] == date2[2]) return true; else return false; } }