List of usage examples for java.util Calendar DATE
int DATE
To view the source code for java.util Calendar DATE.
Click Source Link
get
and set
indicating the day of the month. From source file:Main.java
public static int getAge(String year, String month, String day) throws NumberFormatException { int yearInt = Integer.parseInt(year); int monthInt = Integer.parseInt(month); int dayInt = Integer.parseInt(day); monthInt--;/*from w w w. j a v a 2 s. com*/ Calendar birthCal = Calendar.getInstance(); birthCal.set(yearInt, monthInt, dayInt); Calendar todayCal = Calendar.getInstance(); int diff = todayCal.get(Calendar.YEAR) - birthCal.get(Calendar.YEAR); if (birthCal.get(Calendar.MONTH) > todayCal.get(Calendar.MONTH) || (birthCal.get(Calendar.MONTH) == todayCal.get(Calendar.MONTH) && birthCal.get(Calendar.DATE) > todayCal.get(Calendar.DATE))) { diff--; } return diff; }
From source file:Main.java
public static Calendar getWallpaperDate(Context context) { Calendar wallpaperDate = Calendar.getInstance(); SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context); String dateTimeToString = preferences.getString("wallpaper_date", null); if (dateTimeToString == null) return wallpaperDate; wallpaperDate.set(Calendar.YEAR, Integer.parseInt(dateTimeToString.split("/")[0])); wallpaperDate.set(Calendar.MONTH, Integer.parseInt(dateTimeToString.split("/")[1])); wallpaperDate.set(Calendar.DATE, Integer.parseInt(dateTimeToString.split("/")[2])); return wallpaperDate; }
From source file:Main.java
static void setDate(Calendar cal, int month, int date) { cal.clear();/*from w w w. j av a 2 s . co m*/ cal.set(Calendar.YEAR, Calendar.getInstance().get(Calendar.YEAR)); cal.set(Calendar.MONTH, month); cal.set(Calendar.DATE, date); cal.set(Calendar.HOUR_OF_DAY, 0); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); }
From source file:Main.java
public static boolean equalDate(String date) { Date todayDate = null;//from ww w.ja v a 2 s. c o m Date inputDate = null; Date thirdDate = null; SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); String today = sdf.format(new Date()); Calendar cal = Calendar.getInstance(); // cal.add(Calendar.DATE, -1); // String today = sdf.format(cal.getTime()); try { todayDate = sdf.parse(today); inputDate = sdf.parse(date); cal.setTime(inputDate); cal.add(Calendar.DATE, 3); thirdDate = cal.getTime(); if (todayDate.compareTo(inputDate) >= 0 && todayDate.compareTo(thirdDate) < 0) { return true; } else { return false; } } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); return false; } }
From source file:Main.java
static void setDate(Calendar cal, int month, int date, boolean endOfDay) { cal.clear();//from w ww . j a v a2 s . c o m cal.set(Calendar.YEAR, Calendar.getInstance().get(Calendar.YEAR)); cal.set(Calendar.MONTH, month); cal.set(Calendar.DATE, date); if (endOfDay) { cal.set(Calendar.HOUR_OF_DAY, 23); cal.set(Calendar.MINUTE, 59); cal.set(Calendar.SECOND, 59); cal.set(Calendar.MILLISECOND, 999); } else { cal.set(Calendar.HOUR_OF_DAY, 0); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); } }
From source file:Main.java
private static Date getTomorrowMorning4am() { Calendar tomorrow = new GregorianCalendar(); tomorrow.add(Calendar.DATE, fONE_DAY); Calendar result = new GregorianCalendar(tomorrow.get(Calendar.YEAR), tomorrow.get(Calendar.MONTH), tomorrow.get(Calendar.DATE), fFOUR_AM, fZERO_MINUTES); return result.getTime(); }
From source file:Main.java
/** * Get last month first day/* ww w . ja v a 2s .c om*/ */ public static int getLastMonthFirstDay() { Calendar lastDate = Calendar.getInstance(); lastDate.set(Calendar.DATE, 1); lastDate.add(Calendar.MONTH, -1); return lastDate.getActualMinimum(Calendar.DAY_OF_MONTH); }
From source file:Main.java
@SuppressLint("SimpleDateFormat") static String futureDate() { // take current date and increment Calendar cal = Calendar.getInstance(TimeZone.getDefault()); Date currentLocalTime = cal.getTime(); SimpleDateFormat date = new SimpleDateFormat("yyyy-MM-dd"); date.setTimeZone(TimeZone.getDefault()); _currentDate = date.format(currentLocalTime); try {/*from www. jav a2 s . c o m*/ cal.setTime(date.parse(_currentDate)); } catch (ParseException e) { e.printStackTrace(); } cal.add(Calendar.DATE, 30); _currentDate = date.format(cal.getTime()); return _currentDate; }
From source file:Main.java
/** * Get last month end day//from w w w . ja v a 2 s. c o m */ public static int getLastMonthEndDay() { Calendar lastDate = Calendar.getInstance(); lastDate.add(Calendar.MONTH, -1); lastDate.set(Calendar.DATE, 1); lastDate.roll(Calendar.DATE, -1); return lastDate.getActualMaximum(Calendar.DAY_OF_MONTH); }
From source file:Main.java
/** * Get next month first day/*from w w w.ja v a 2s. c om*/ */ public static int getNextMonthFirstDay() { Calendar lastDate = Calendar.getInstance(); lastDate.add(Calendar.MONTH, 1); lastDate.set(Calendar.DATE, 1); return lastDate.getActualMinimum(Calendar.DAY_OF_MONTH); }