List of usage examples for java.util Calendar add
public abstract void add(int field, int amount);
From source file:Main.java
/** * Returns yesterday's date formatted according to the HTTP specification * standard date format./*from w w w.j av a 2s. co m*/ * * @return a formatted string. */ public static String getExpiredHttpDateString() { Calendar cal = Calendar.getInstance(); cal.add(Calendar.DAY_OF_YEAR, -1); return getHttpDateString(cal.getTime()); }
From source file:Main.java
/** * Get next month first day/*from w ww .j av a2 s . co m*/ */ 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); }
From source file:Main.java
public static String getDateFormattedRecent(Date date, int daysAgo) { //display day of the week for activities occurred in the last daysAgo Calendar calendar = Calendar.getInstance(); calendar.add(Calendar.DATE, 0 - daysAgo); Date weekAgo = calendar.getTime(); if (date.after(weekAgo)) { return new SimpleDateFormat("EEE").format(date);//EEE, short version of day of the week }// w w w . ja va2 s.c o m //otherwise, display the date of the activity else { return new SimpleDateFormat("MM.dd.yy").format(date); } }
From source file:Main.java
/** * Get last month end day/* w w w.ja va 2 s. c om*/ */ 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
public static Date addDays(Date date, int days) { Calendar cal = Calendar.getInstance(); cal.setTime(date);//from ww w . j a v a2 s .com cal.add(Calendar.DATE, days); //minus number would decrement the days return cal.getTime(); }
From source file:Main.java
/** * Get next month end day//from w w w . j a v a2s. c o m * * @return */ public static int getNextMonthEndDay() { 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
private static Calendar add(long time, int val, int field) { Calendar c = Calendar.getInstance(); c.setTimeInMillis(time);//from ww w . j a va 2 s .c om c.add(field, val); return c; }
From source file:Main.java
public static void addCalendarMinute(Calendar cal, int minutes) { cal.add(Calendar.MINUTE, minutes); }
From source file:Main.java
public static Date addFiveMinutes(Date date) { Calendar cal = Calendar.getInstance(); cal.setTime(date);//from w w w .j a va 2s . c o m cal.add(Calendar.MINUTE, 5); return cal.getTime(); }
From source file:Main.java
public static Date addHours(Date date, int hours) { Calendar cal = Calendar.getInstance(); cal.setTime(date);//w w w . java 2 s .c om cal.add(Calendar.HOUR_OF_DAY, hours); return cal.getTime(); }