List of usage examples for java.util Calendar add
public abstract void add(int field, int amount);
From source file:Main.java
/** * @param days// ww w . ja v a2 s.c o m * number of days after September 02, 1975 (what happened on this * day?) * @return */ public static Calendar getDayFromQuickLogEntry(int days) { Calendar logDay = GregorianCalendar.getInstance(); logDay.set(Calendar.DAY_OF_MONTH, 2); logDay.set(Calendar.MONTH, Calendar.SEPTEMBER); logDay.set(Calendar.YEAR, 1975); logDay.add(Calendar.DAY_OF_YEAR, days); return logDay; }
From source file:com.jennifer.ui.util.TimeUtil.java
public static Date add(Date d, String type, int interval) { Calendar c = Calendar.getInstance(); c.setTime(d);/*from w w w. ja v a 2 s .com*/ if (Time.YEARS.equals(type)) { c.add(Calendar.YEAR, interval); } else if (Time.MONTHS.equals(type)) { c.add(Calendar.MONTH, interval); } else if (Time.DAYS.equals(type)) { c.add(Calendar.DATE, interval); } else if (Time.HOURS.equals(type)) { c.add(Calendar.HOUR_OF_DAY, interval); } else if (Time.MINUTES.equals(type)) { c.add(Calendar.MINUTE, interval); } else if (Time.SECONDS.equals(type)) { c.add(Calendar.SECOND, interval); } else if (Time.MILLISECONDS.equals(type)) { c.add(Calendar.MILLISECOND, interval); } else if (Time.WEEKS.equals(type)) { c.add(Calendar.DATE, interval * 7); } return c.getTime(); }
From source file:ee.ria.xroad.asyncsender.AsyncSenderIntegrationTest.java
private static Date getDate(int min, int sec) { Calendar cal = Calendar.getInstance(); cal.add(Calendar.MINUTE, min); cal.add(Calendar.SECOND, sec); return cal.getTime(); }
From source file:com.amazonaws.sqs.util.SQSClient.java
private static String getExpires() { Calendar cal = Calendar.getInstance(); cal.add(Calendar.MINUTE, 60); SimpleTimeZone timeZone = new SimpleTimeZone(0, "PST"); SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssz"); format.setTimeZone(timeZone);/*from w ww. j av a2 s. co m*/ String timestampStr = format.format(cal.getTime()); return timestampStr; }
From source file:com.adaptris.core.LogHandlerTest.java
public static List<Long> createLogFiles(File dir, String prefix, int count) throws Exception { ensureDirectory(dir);/* w ww . j a v a 2 s . c o m*/ ArrayList<Long> ages = new ArrayList<Long>(); // Shoudld give us files ranging from 9 days in the past to 1hour in the // past. for (int i = count - 1; i >= 0; i--) { Calendar c = Calendar.getInstance(); c.add(Calendar.DAY_OF_YEAR, 0 - i); c.add(Calendar.MINUTE, -1); ages.add(c.getTimeInMillis()); } for (Long age : ages) { File f = File.createTempFile(prefix, null, dir); f.setLastModified(age); } return ages; }
From source file:Main.java
private static void prepareCalendarStartsMonday(Calendar calendar) { if (calendar.get(Calendar.DAY_OF_WEEK) != Calendar.MONDAY) { int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK); if (dayOfWeek == Calendar.SUNDAY) { calendar.add(Calendar.DATE, -6); } else {//from www .j a v a 2s .c om calendar.add(Calendar.DATE, -dayOfWeek + 2); } } }
From source file:MainGeneratePicasaIniFile.java
public static long daysBetween(Calendar startDate, Calendar endDate) { Calendar date = (Calendar) startDate.clone(); long daysBetween = 0; while (date.before(endDate)) { date.add(Calendar.DAY_OF_MONTH, 1); daysBetween++;//from w w w .j a v a 2s . c o m } return daysBetween; }
From source file:eionet.gdem.qa.WQCleanerJob.java
/** * Check the job's age and return true if it is possible to delete it. * * @param job/*from www . j ava2 s . c o m*/ * Workqueue job object * @return true if job can be deleted. */ public static boolean canDeleteJob(WorkqueueJob job) { boolean canDelete = false; if (job != null && job.getJobTimestamp() != null && job.getStatus() >= Constants.XQ_READY) { Calendar now = Calendar.getInstance(); int maxAge = Properties.wqJobMaxAge == 0 ? -1 : -Properties.wqJobMaxAge; now.add(Calendar.HOUR, maxAge); Calendar jobCal = Calendar.getInstance(); jobCal.setTime(job.getJobTimestamp()); if (now.after(jobCal)) { canDelete = true; } } return canDelete; }
From source file:Main.java
public static String getStringByOffset(String strDate, String format, int calendarField, int offset) { String mDateTime = null;// w ww . j ava 2s .co m try { Calendar c = new GregorianCalendar(); SimpleDateFormat mSimpleDateFormat = new SimpleDateFormat(format); c.setTime(mSimpleDateFormat.parse(strDate)); c.add(calendarField, offset); mDateTime = mSimpleDateFormat.format(c.getTime()); } catch (ParseException e) { e.printStackTrace(); } return mDateTime; }
From source file:Main.java
public static String getStringByOffset(String strDate, String format, int calendarField, int offset) { String mDateTime = null;/* w w w . j a va 2 s .c o m*/ try { Calendar c = new GregorianCalendar(); SimpleDateFormat mSimpleDateFormat = new SimpleDateFormat(format, Locale.CHINA); c.setTime(mSimpleDateFormat.parse(strDate)); c.add(calendarField, offset); mDateTime = mSimpleDateFormat.format(c.getTime()); } catch (ParseException e) { e.printStackTrace(); } return mDateTime; }