List of usage examples for java.util Calendar add
public abstract void add(int field, int amount);
From source file:com.zuora.api.util.ZuoraUtility.java
/** * Gets the end date.//from w w w. ja va 2 s . c o m * * @return the end date */ public static Calendar getNextMonth() { Calendar nextMonthDate = Calendar.getInstance(); nextMonthDate.add(Calendar.MONTH, 1); return nextMonthDate; }
From source file:com.zuora.api.util.ZuoraUtility.java
/** * Gets the end date./*from w ww. j ava2 s. c o m*/ * * @return the end date */ public static Calendar getEndDate() { Calendar calendarEndDate = Calendar.getInstance(); calendarEndDate.add(Calendar.YEAR, 1); return calendarEndDate; }
From source file:Main.java
/** Converts a Macintosh-style timestamp (seconds since * January 1, 1904) into a Java date. The timestamp is * treated as a time in the default localization. * Depending on that localization,// ww w . j av a2s. c o m * there may be some variation in the exact hour of the date * returned, e.g., due to daylight savings time. * */ public static Date timestampToDate(long timestamp) { Calendar cal = Calendar.getInstance(); cal.set(1904, 0, 1, 0, 0, 0); // If we add the seconds directly, we'll truncate the long // value when converting to int. So convert to hours plus // residual seconds. int hours = (int) (timestamp / 3600); int seconds = (int) (timestamp - (long) hours * 3600L); cal.add(Calendar.HOUR_OF_DAY, hours); cal.add(Calendar.SECOND, seconds); Date dat = cal.getTime(); return dat; }
From source file:org.onebusaway.webapp.actions.where.ScheduleAction.java
private static Date getShiftedDateStatic(Date date) { Calendar c = Calendar.getInstance(); c.setTime(date);//from w w w.j a v a2 s . c om c.add(Calendar.HOUR_OF_DAY, 12); return c.getTime(); }
From source file:helper.util.DateHelper.java
/** * @return the days between two calendars, including dealing with year boundary **//*from www . j a va 2 s .com*/ public static int calculateIntervalInDays(CalendarRange range) { Calendar start = range.getStart(); Calendar end = range.getEnd(); int startYear = start.get(Calendar.YEAR); int endYear = end.get(Calendar.YEAR); if (startYear == endYear) { if (start.get(Calendar.DAY_OF_YEAR) == end.get(Calendar.DAY_OF_YEAR)) { return 0; } return end.get(Calendar.DAY_OF_YEAR) - start.get(Calendar.DAY_OF_YEAR); } else if (start.getTimeInMillis() < end.getTimeInMillis()) { // let the calendar do the thinking, just increment date until we hit our end date Calendar startCopy = (Calendar) start.clone(); int days = 0; while (true) { startCopy.add(Calendar.DATE, 1); days++; if (startCopy.get(Calendar.DAY_OF_YEAR) == end.get(Calendar.DAY_OF_YEAR)) { return days; } } } else { // let the calendar do the thinking, just increment date until we hit our end date Calendar startCopy = (Calendar) start.clone(); int days = 0; while (true) { startCopy.add(Calendar.DATE, -1); days--; if (startCopy.get(Calendar.DAY_OF_YEAR) == end.get(Calendar.DAY_OF_YEAR)) { return days; } } } }
From source file:dumbara.view.Chart1.java
public static void byAgent() { DefaultPieDataset objDataset = new DefaultPieDataset(); try {//from w ww .j a v a2s . c o m Chart[] charts = SalesController.getAgencyAmounts(); for (Chart chart : charts) { objDataset.setValue(chart.getAgencyID(), chart.getIncomeSum()); } } catch (ClassNotFoundException | SQLException ex) { Logger.getLogger(Chart1.class.getName()).log(Level.SEVERE, null, ex); } Calendar cal = Calendar.getInstance(); cal.add(Calendar.MONTH, -1); Date result = cal.getTime(); SimpleDateFormat simpleDateFormat = new SimpleDateFormat("E yyyy.MM.dd"); String format = simpleDateFormat.format(result); Date date = new Date(); String format1 = simpleDateFormat.format(date); JFreeChart objChart = ChartFactory.createPieChart( "Sales Range of Agencies from " + format + " to " + format1, objDataset, true, true, false); ChartFrame frame = new ChartFrame("Data Analysis Wizard - v2.1.4", objChart); frame.pack(); frame.setVisible(true); frame.setLocationRelativeTo(null); }
From source file:org.wiztools.commons.DateUtil.java
private static Date getDatePlus(final int unit, final Date date, final int quantity) { Calendar c = Calendar.getInstance(); c.clear();// www .j a v a 2s.co m c.setTime(date); c.add(unit, quantity); return c.getTime(); }
From source file:com.gatf.executor.core.GatfFunctionHandler.java
public static String handleFunction(String function) { if (function.equals(BOOLEAN)) { Random rand = new Random(); return String.valueOf(rand.nextBoolean()); } else if (function.matches(DT_FMT_REGEX)) { Matcher match = datePattern.matcher(function); match.matches();//from w w w . jav a2 s. co m SimpleDateFormat format = new SimpleDateFormat(match.group(1)); return format.format(new Date()); } else if (function.matches(DT_FUNC_FMT_REGEX)) { Matcher match = specialDatePattern.matcher(function); match.matches(); String formatStr = match.group(1); String operation = match.group(2); int value = Integer.valueOf(match.group(3)); String unit = match.group(4); SimpleDateFormat format = new SimpleDateFormat(formatStr); try { Date dt = format.parse(format.format(new Date())); Calendar cal = Calendar.getInstance(); cal.setTime(dt); value = (operation.equals(MINUS) ? -value : value); if (unit.equals(YEAR)) { cal.add(Calendar.YEAR, value); } else if (unit.equals(MONTH)) { cal.add(Calendar.MONTH, value); } else if (unit.equals(DAY)) { cal.add(Calendar.DAY_OF_YEAR, value); } else if (unit.equals(HOUR)) { cal.add(Calendar.HOUR_OF_DAY, value); } else if (unit.equals(MINUITE)) { cal.add(Calendar.MINUTE, value); } else if (unit.equals(SECOND)) { cal.add(Calendar.SECOND, value); } else if (unit.equals(MILLISECOND)) { cal.add(Calendar.MILLISECOND, value); } return format.format(cal.getTime()); } catch (Exception e) { throw new AssertionError("Invalid date format specified - " + formatStr); } } else if (function.equals(FLOAT)) { Random rand = new Random(12345678L); return String.valueOf(rand.nextFloat()); } else if (function.equals(ALPHA)) { return RandomStringUtils.randomAlphabetic(10); } else if (function.equals(ALPHANUM)) { return RandomStringUtils.randomAlphanumeric(10); } else if (function.equals(NUMBER_PLUS)) { Random rand = new Random(); return String.valueOf(rand.nextInt(1234567)); } else if (function.equals(NUMBER_MINUS)) { Random rand = new Random(); return String.valueOf(-rand.nextInt(1234567)); } else if (function.equals(NUMBER)) { Random rand = new Random(); boolean bool = rand.nextBoolean(); return bool ? String.valueOf(rand.nextInt(1234567)) : String.valueOf(-rand.nextInt(1234567)); } else if (function.matches(RANDOM_RANGE_REGEX)) { Matcher match = randRangeNum.matcher(function); match.matches(); String min = match.group(1); String max = match.group(2); try { int nmin = Integer.parseInt(min); int nmax = Integer.parseInt(max); return String.valueOf(nmin + (int) (Math.random() * ((nmax - nmin) + 1))); } catch (Exception e) { e.printStackTrace(); } } return null; }
From source file:dumbara.view.Chart1.java
public static void getBottleIncome() { DefaultCategoryDataset objDataset = new DefaultCategoryDataset(); try {//from w w w . j ava2 s. c o m Chart3[] chart3s = SalesController.getBottleIncome(); for (Chart3 chart3 : chart3s) { objDataset.setValue(chart3.getIncome(), "Bottle Income", chart3.getBottleID()); } } catch (ClassNotFoundException | SQLException ex) { Logger.getLogger(Chart1.class.getName()).log(Level.SEVERE, null, ex); } // Calendar cal = Calendar.getInstance(); cal.add(Calendar.MONTH, -1); Date result = cal.getTime(); SimpleDateFormat simpleDateFormat = new SimpleDateFormat("E yyyy.MM.dd"); String format = simpleDateFormat.format(result); Date date = new Date(); String format1 = simpleDateFormat.format(date); JFreeChart objChart = ChartFactory.createBarChart( "Sales Comparisson by Bottle ID from " + format + " to " + format1, "Bottle ID", "Sales Income", objDataset, PlotOrientation.VERTICAL, true, true, false); ChartFrame frame = new ChartFrame("Data Analysis Wizard - v2.1.4", objChart); frame.pack(); frame.setSize(1000, 600); frame.setVisible(true); frame.setLocationRelativeTo(null); }
From source file:dumbara.view.Chart1.java
public static void byIncome() { DefaultCategoryDataset objDataset = new DefaultCategoryDataset(); try {//from w w w. jav a 2s. com Sale[] sale = SalesController.viewAllSales(); for (Sale sale1 : sale) { objDataset.setValue(sale1.getIncome(), "Sales Progress", sale1.getSalesID()); } } catch (ClassNotFoundException | SQLException ex) { Logger.getLogger(Chart1.class.getName()).log(Level.SEVERE, null, ex); } Calendar cal = Calendar.getInstance(); cal.add(Calendar.MONTH, -1); Date result = cal.getTime(); SimpleDateFormat simpleDateFormat = new SimpleDateFormat("E yyyy.MM.dd"); String format = simpleDateFormat.format(result); Date date = new Date(); String format1 = simpleDateFormat.format(date); JFreeChart objChart = ChartFactory.createBarChart( "Sales Comparisson by Sales ID from " + format + " to " + format1, "Sales ID", "Sales Income", objDataset, PlotOrientation.VERTICAL, true, true, false ); ChartFrame frame = new ChartFrame("Data Analysis Wizard - v2.1.4", objChart); frame.pack(); frame.setSize(1300, 600); frame.setVisible(true); frame.setLocationRelativeTo(null); }