List of usage examples for java.util Calendar add
public abstract void add(int field, int amount);
From source file:Main.java
public static Date weekDayOfWeek(Date startWeekDate, int day) { Calendar calendar = Calendar.getInstance(Locale.GERMANY); calendar.setTime(startWeekDate);/*from w w w. j a va 2 s .c o m*/ calendar.add(Calendar.DAY_OF_YEAR, day); return calendar.getTime(); }
From source file:Main.java
/** * Determines the Date "date" adjusted by "days". * A negative value will return a date in the past. * @param date The date to be adjusted//from w w w. j a v a 2 s .co m * @param days The number of days to adjust by * @return Returns a date object */ public static Date getDateAdjustedByDays(Date date, int days) { Calendar cal = Calendar.getInstance(); if (date != null) cal.setTime(date); cal.add(Calendar.DAY_OF_YEAR, days); return cal.getTime(); }
From source file:Main.java
public static Date getLastWeekOfYear(Date date) { // Set time/*w ww . j a v a2 s .c om*/ Calendar calendar = Calendar.getInstance(); calendar.setTime(date); // Go to last week calendar.add(Calendar.WEEK_OF_YEAR, -1); return calendar.getTime(); }
From source file:Main.java
/** * Returns date before given days// w w w.j a v a 2s . c om * * @param days days to before * @return string date string before days */ public static String getDateBefore(int days) { Date today = new Date(); Calendar cal = new GregorianCalendar(); cal.setTime(today); cal.add(Calendar.DAY_OF_MONTH, days * -1); Date date = cal.getTime(); SimpleDateFormat gmtFormat = new SimpleDateFormat(); gmtFormat.applyPattern("yyyy-MM-dd 00:00:00"); TimeZone gmtTime = TimeZone.getTimeZone("GMT"); gmtFormat.setTimeZone(gmtTime); return gmtFormat.format(date); }
From source file:Main.java
private static Calendar add(long time, int val, int field) { Calendar c = Calendar.getInstance(); c.setTimeInMillis(time);//from w ww.ja v a 2 s.com if (field == 666) { c.add(Calendar.MONTH, val * 3); } else { c.add(field, val); } return c; }
From source file:Main.java
/** * Takes in a duration in minutes and a start timestamp and returns * the formatted time that is timestamp + duration *//* w w w . j a v a2s. c om*/ public static String getTimeAfterStart(long startTime, int duration) { Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(startTime); calendar.add(Calendar.MINUTE, duration); int minute = calendar.get(Calendar.MINUTE); String minuteString = ""; if (minute < 10) minuteString = "0" + minute; else minuteString = "" + minute; String timeString = calendar.get(Calendar.HOUR) + ":" + minuteString + " " + AM_PM[calendar.get(Calendar.AM_PM)]; return timeString; }
From source file:Main.java
static Date getExpirationDate(int tokenExpiredDateInMinuite) { final Calendar expiredTime = new GregorianCalendar(); // access token is only valid for a hour expiredTime.add(Calendar.MINUTE, tokenExpiredDateInMinuite); return expiredTime.getTime(); }
From source file:Main.java
public static Calendar nextDayOfWeek(int dow) { Calendar date = Calendar.getInstance(); int diff = dow - date.get(Calendar.DAY_OF_WEEK); if (!(diff > 0)) { diff += 7;/*from w ww .j a va 2 s .c om*/ } date.add(Calendar.DAY_OF_MONTH, diff); return date; }
From source file:Main.java
public static Date startOfNextWeek() { Calendar cal = Calendar.getInstance(); cal.setTime(startOfThisWeek());/*from w w w. ja v a2 s .c om*/ cal.add(Calendar.WEEK_OF_YEAR, 1); return cal.getTime(); }
From source file:com.microsoft.live.TestUtils.java
public static LiveConnectSession newMockLiveConnectSession() { LiveAuthClient authClient = TestUtils.newMockLiveAuthClient(); LiveConnectSession session = new LiveConnectSession(authClient); session.setAccessToken("access_token"); session.setAuthenticationToken("authentication_token"); Calendar calendar = Calendar.getInstance(); calendar.add(Calendar.SECOND, 3600); session.setExpiresIn(calendar.getTime()); String[] scopes = { "scope" }; session.setScopes(Arrays.asList(scopes)); session.setRefreshToken("refresh_token"); session.setTokenType("token_type"); return session; }