List of usage examples for java.util Calendar add
public abstract void add(int field, int amount);
From source file:Main.java
public static String getTimeAndDate(long j) { try {//from ww w. jav a 2s . c om Calendar instance = Calendar.getInstance(); TimeZone timeZone = TimeZone.getDefault(); instance.setTimeInMillis(j); instance.add(14, timeZone.getOffset(instance.getTimeInMillis())); String format = new SimpleDateFormat(" dd, MMM yyyy").format(instance.getTime()); Time time = new Time(); time.set(j); return time.format("%H:%M") + format; } catch (Exception e) { return ""; } }
From source file:Main.java
public static int[] getWeekSunday(int year, int month, int day, int pervious) { int[] time = new int[3]; Calendar c = Calendar.getInstance(); c.set(Calendar.YEAR, year);// w w w . j a va 2 s . c o m c.set(Calendar.MONTH, month); c.set(Calendar.DAY_OF_MONTH, day); c.add(Calendar.DAY_OF_MONTH, pervious); time[0] = c.get(Calendar.YEAR); time[1] = c.get(Calendar.MONTH) + 1; time[2] = c.get(Calendar.DAY_OF_MONTH); return time; }
From source file:com.beligum.core.accounts.UserManager.java
public static void storeCurrentUser(User user) { Http.Context.current().session().put(SESSION_KEY_USER, user.getId().toString()); Calendar timeOut = DateTimeHelper.getCurrentTime(); timeOut.add(Calendar.HOUR, 1); Http.Context.current().session().put(SESSION_KEY_TIMEOUT, DateTimeHelper.formatDate(timeOut, "dd/MM/yyyy HH:mm")); }
From source file:Main.java
public static Calendar nextBirthday(Calendar today, Calendar dayOfBirth) { Calendar nextBirthday = (Calendar) dayOfBirth.clone(); nextBirthday.set(Calendar.YEAR, today.get(Calendar.YEAR)); if (nextBirthday.before(today)) { nextBirthday.add(Calendar.YEAR, 1); }/*from w ww .j a va2 s.c om*/ return nextBirthday; }
From source file:Main.java
public static String calcUntil(Calendar untilDate, String granularity) { String pattern = ""; if (granularity.equals("YYYY-MM-DDThh:mm:ssZ")) { untilDate.add(Calendar.SECOND, -1); pattern = "yyyy-MM-dd'T'HH:mm:ss'Z'"; } else {/*from www .j a v a 2 s . c o m*/ untilDate.add(Calendar.DATE, -1); pattern = "yyyy-MM-dd"; } SimpleDateFormat sdf = new SimpleDateFormat(pattern); sdf.setTimeZone(TimeZone.getTimeZone("UTC")); return sdf.format(untilDate.getTime()); }
From source file:com.dhenton9000.selenium.generic.UtilMethods.java
public static String getPreviousDate(int daysAgo) { DateFormat newFormat = new SimpleDateFormat("MM/dd/yyyy"); newFormat.setLenient(true);/* w w w .ja va2 s .c om*/ Calendar cal = Calendar.getInstance(); cal.setTime(new java.util.Date()); cal.add(Calendar.DATE, -1 * daysAgo); return newFormat.format(cal.getTime()); }
From source file:Main.java
public static Date hourRoundPlusHour(Date date, int n) { Calendar calendar = Calendar.getInstance(); calendar.setTime(date);/*from w ww. j a v a 2 s. co m*/ calendar.set(Calendar.SECOND, 0); calendar.set(Calendar.MINUTE, 0); calendar.add(Calendar.HOUR_OF_DAY, n); return calendar.getTime(); }
From source file:Main.java
public static Date getTimeCurrent() { Calendar cal = Calendar.getInstance(); Date timeNow = new Date(); cal.setTime(timeNow);// w ww . ja va2 s . co m // Um numero negativo vai decrementar a data cal.add(Calendar.MILLISECOND, TimeZone.getDefault().getOffset(timeNow.getTime()) * -1); return cal.getTime(); }
From source file:Main.java
private static long calcTimeBettwenZeroAndNow() { Calendar calendar = Calendar.getInstance(Locale.CHINA); calendar.setTimeInMillis(System.currentTimeMillis()); int currentHour = calendar.get(calendar.HOUR); calendar.add(Calendar.HOUR, 24 - currentHour); return calendar.getTimeInMillis(); }
From source file:com.intuit.tank.util.TimeFormatUtil.java
public static String formatTime(int numSeconds) { Calendar c = Calendar.getInstance(TimeZone.getTimeZone("GMT")); c.setTimeInMillis(0);//from ww w. j a v a 2s .c o m c.add(Calendar.SECOND, numSeconds); return DF.format(c); }