List of usage examples for java.util Calendar getActualMaximum
public int getActualMaximum(int field)
Calendar
. From source file:Main.java
public static List<Integer> getAllDayInMonth(int month, int year) { List<Integer> listDate = new ArrayList<Integer>(); Calendar calendar = Calendar.getInstance(); calendar.set(year, month, 1);/*from ww w.j a v a2s .c om*/ calendar.clear(Calendar.HOUR); calendar.clear(Calendar.MINUTE); calendar.clear(Calendar.SECOND); int totalDays = calendar.getActualMaximum(Calendar.DAY_OF_MONTH); for (int i = 1; i <= totalDays; i++) { listDate.add(i); } return listDate; }
From source file:Main.java
/** * Using the expiry date, generate the application end date in the correct format. * * @param expiryMonth Month of expiry./* w w w. j a v a2 s . c om*/ * @param expiryYear Year of expiry. * @return The application end date in the correct format. */ private static String generateExpiryDate(String expiryMonth, String expiryYear) { // Just combine the year and month String applicationEndDate = expiryYear + expiryMonth; // Now need to work out the last day of the month // NB: Calendar's months range from 0-11 rather than 1-12 Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.YEAR, Integer.parseInt(expiryYear)); calendar.set(Calendar.MONTH, Integer.parseInt(expiryMonth) - 1); applicationEndDate += calendar.getActualMaximum(Calendar.DATE); return applicationEndDate; }
From source file:Main.java
public static Date startOfThisMonth(int startDayOfMonth) { Calendar cal = Calendar.getInstance(); if (cal.get(Calendar.DATE) < startDayOfMonth) // the start is startDayOfMonth, last month cal.add(Calendar.MONTH, -1); int lastDayInMonth = cal.getActualMaximum(Calendar.DAY_OF_MONTH); if (startDayOfMonth <= lastDayInMonth) cal.set(Calendar.DATE, startDayOfMonth); else {/*from ww w .j a v a 2 s .c o m*/ cal.add(Calendar.MONTH, 1); cal.set(Calendar.DATE, 1); } return startOfDay(cal.getTime()); }
From source file:Main.java
public static Date startOfNextMonth(int startDayOfMonth) { Calendar cal = Calendar.getInstance(); if (cal.get(Calendar.DATE) >= startDayOfMonth)// the end is one day past startDayOfMonth, next month cal.add(Calendar.MONTH, 1); int lastDayInMonth = cal.getActualMaximum(Calendar.DAY_OF_MONTH); if (startDayOfMonth < lastDayInMonth) cal.set(Calendar.DATE, startDayOfMonth + 1); else {//from www .ja v a 2s. c o m cal.add(Calendar.MONTH, 1); cal.set(Calendar.DATE, 1); } return startOfDay(cal.getTime()); }
From source file:com.qdum.llhb.common.utils.DateUtils.java
/** * getMonthLastDay??:???//from w w w. j av a2s . com * * @author yaoyt * @time 15/12/29 ?1:21 */ public static Date getMonthLastDay() { Calendar c = Calendar.getInstance(); c.set(Calendar.DAY_OF_MONTH, c.getActualMaximum(Calendar.DAY_OF_MONTH)); return c.getTime(); }
From source file:DateTimeUtil.java
/** * // w ww . j av a 2 s .c om * @param month * @param year * @return */ public static final int getlastDateofThisMonth(int month, int year) { Calendar calendar = Calendar.getInstance(); if (year > -1) { calendar.set(Calendar.YEAR, year); } if (month > -1) { month--; calendar.set(Calendar.MONTH, month); } return calendar.getActualMaximum(Calendar.DATE); }
From source file:Main.java
/** * Returns two days old date from the current date. This is used with forusquare web service to get the data * according to date./*from www. j a v a2 s. com*/ * * @return date in string. */ public static String getTwoDaysOldDate() { int yyyy = Calendar.getInstance().get(Calendar.YEAR); int MM = Calendar.getInstance().get(Calendar.MONTH) + 1; int dd = Calendar.getInstance().get(Calendar.DATE) - 2; Calendar cal = Calendar.getInstance(); if (dd < 1) { MM = MM - 1; if (MM < 0) { MM = 0; } } if (MM < 0) { yyyy = yyyy - 1; } cal.set(yyyy, MM, 1); dd = cal.getActualMaximum(Calendar.DATE) - dd; String oldDate = String.format("%04d%02d%02d", yyyy, MM, dd); return oldDate; }
From source file:org.openlmis.performancetesting.Utils.java
public static Date periodEndDate(int year, int month) { Calendar calendar = Calendar.getInstance(); calendar.set(year, month - 1, 1);/*w w w.j ava2s .com*/ calendar.set(HOUR_OF_DAY, 0); calendar.set(MINUTE, 0); calendar.set(SECOND, 0); calendar.set(MILLISECOND, 0); int numOfDaysInMonth = calendar.getActualMaximum(DAY_OF_MONTH); calendar.add(DAY_OF_MONTH, numOfDaysInMonth); calendar.set(MILLISECOND, -1); return calendar.getTime(); }
From source file:org.eclipse.smarthome.binding.astro.internal.util.DateTimeUtils.java
/** * Returns the year of the calendar object as a decimal value. *//*from w w w .j a va2 s.co m*/ public static double getDecimalYear(Calendar calendar) { return calendar.get(Calendar.YEAR) + (double) calendar.get(Calendar.DAY_OF_YEAR) / calendar.getActualMaximum(Calendar.DAY_OF_YEAR); }
From source file:com.nabla.dc.server.handler.fixed_asset.Asset.java
static public void dispose(final Connection conn, final Integer assetId, final IDisposal disposal) throws SQLException, DispatchException { final PreparedStatement redo = conn .prepareStatement("INSERT INTO fa_transaction_redo (fa_asset_id, command) VALUES(?,?);"); try {/* w ww .j a v a 2 s . c o m*/ redo.setInt(1, assetId); // backup transaction after disposal if any if (log.isDebugEnabled()) log.debug("backing up transactions after disposal date"); // charge monthly depreciation in disposal month if disposal is after 15 final Calendar dt = Util.dateToCalendar(disposal.getDate()); if (dt.get(GregorianCalendar.DAY_OF_MONTH) >= dt.getActualMaximum(GregorianCalendar.DAY_OF_MONTH) / 2) dt.add(GregorianCalendar.MONTH, 1); dt.set(GregorianCalendar.DAY_OF_MONTH, 1); final Date from = Util.calendarToSqlDate(dt); // get list of transactions to backup before we delete them final IntegerSet transIds = new IntegerSet(); final PreparedStatement stmt = StatementFormat.prepare(conn, "SELECT t.*" + " FROM fa_transaction AS t INNER JOIN period_end AS p ON t.period_end_id=p.id" + " WHERE t.fa_asset_id=? AND p.end_date>?;", assetId, from); try { final ResultSet rs = stmt.executeQuery(); try { while (rs.next()) { transIds.add(rs.getInt("id")); final String command = MessageFormat.format("INSERT INTO fa_transaction" + " (id,fa_asset_id,period_end_id,amount,class,type,depreciation_period)" + " VALUES({0,number,0},{1,number,0},{2,number,0},{3,number,0},''{4}'',''{5}'',{6,number,0});", rs.getInt("id"), rs.getInt("fa_asset_id"), rs.getInt("period_end_id"), rs.getInt("amount"), rs.getString("class"), rs.getString("type"), Database.getInteger(rs, "depreciation_period")); if (log.isTraceEnabled()) log.trace("redo = " + command); redo.setString(2, command); redo.addBatch(); } } finally { rs.close(); } } finally { stmt.close(); } // remove any transaction after disposal date if (log.isDebugEnabled()) log.debug("removing transactions after disposal date"); Database.executeUpdate(conn, "DELETE FROM fa_transaction WHERE id IN (?);", transIds); // add disposal transactions if (log.isDebugEnabled()) log.debug("adding transactions for disposal"); final TransactionList transactions = new TransactionList(assetId); // closing cost transactions.add(new Transaction(TransactionClasses.COST, TransactionTypes.CLOSING, disposal.getDate(), -1 * getAssetCostBeforeDisposal(conn, assetId))); // closing accumulated depreciation transactions.add(new Transaction(TransactionClasses.DEP, TransactionTypes.CLOSING, disposal.getDate(), -1 * getAssetDepreciationBeforeDisposal(conn, assetId))); for (Integer newTransId : transactions.save(conn, true)) { redo.setString(2, MessageFormat.format("DELETE FROM fa_transaction WHERE id={0,number,0};", newTransId)); redo.addBatch(); } if (!Database.isBatchCompleted(redo.executeBatch())) throw new InternalErrorException("failed to save disposal transactions"); } finally { redo.close(); } }