List of usage examples for java.util Calendar SECOND
int SECOND
To view the source code for java.util Calendar SECOND.
Click Source Link
get
and set
indicating the second within the minute. From source file:org.tsm.concharto.audit.IntegrationTestAuditEntry.java
@Before public void setUp() { Calendar cal = new GregorianCalendar(107 + 1900, 8, 22, 12, 22, 3); cal.set(Calendar.MILLISECOND, 750); begin = cal.getTime();//from w ww . jav a 2 s .c om cal.set(Calendar.SECOND, 35); end = cal.getTime(); }
From source file:HSSFDateUtil.java
/** * Given a Date, converts it into a double representing its internal Excel * representation, which is the number of days since 1/1/1900. Fractional days * represent hours, minutes, and seconds. * //from w ww . j av a 2 s. com * @return Excel representation of Date (-1 if error - test for error by * checking for less than 0.1) * @param date * the Date */ public static double getExcelDate(final Date date) { Calendar calStart = new GregorianCalendar(); calStart.setTime(date); // If date includes hours, minutes, and seconds, set // them to 0 // if (calStart.get(Calendar.YEAR) < 1900) // { // return BAD_DATE; // } // else // { // Because of daylight time saving we cannot use // date.getTime() - calStart.getTimeInMillis() // as the difference in milliseconds between 00:00 and 04:00 // can be 3, 4 or 5 hours but Excel expects it to always // be 4 hours. // E.g. 2004-03-28 04:00 CEST - 2004-03-28 00:00 CET is 3 hours // and 2004-10-31 04:00 CET - 2004-10-31 00:00 CEST is 5 hours final double fraction = (((calStart.get(Calendar.HOUR_OF_DAY) * 60 + calStart.get(Calendar.MINUTE)) * 60 + calStart.get(Calendar.SECOND)) * 1000 + calStart.get(Calendar.MILLISECOND)) / (double) DAY_MILLISECONDS; calStart = dayStart(calStart); return fraction + (double) absoluteDay(calStart) - CAL_1900_ABSOLUTE; }
From source file:net.seratch.taskun.util.CalendarUtil.java
public static Calendar dateTrunc(Calendar calendar) { if (calendar == null) { return null; }// w w w .jav a2 s . co m Calendar date = (Calendar) calendar.clone(); date.set(Calendar.HOUR_OF_DAY, 0); date.set(Calendar.MINUTE, 0); date.set(Calendar.SECOND, 0); date.set(Calendar.MILLISECOND, 0); return date; }
From source file:Dates.java
/** * Puts hours, minutes, seconds and milliseconds to zero. <p> * /*from w ww. j a va 2s . c om*/ * @return The same date sent as argument (a new date is not created). If null * if sent a null is returned. */ public static Date removeTime(Date date) { if (date == null) return null; Calendar cal = Calendar.getInstance(); cal.setTime(date); cal.set(Calendar.HOUR_OF_DAY, 0); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); date.setTime(cal.getTime().getTime()); return date; }
From source file:sk.lazyman.gizmo.util.GizmoUtils.java
public static Date clearTime(Date date) { if (date == null) { return null; }/* ww w . jav a2s. co m*/ Calendar cal = Calendar.getInstance(); cal.setTime(date); cal.set(Calendar.HOUR_OF_DAY, 0); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); return cal.getTime(); }
From source file:net.groupbuy.controller.admin.SalesController.java
/** * //from w ww.j ava 2s . c om */ @RequestMapping(value = "/view", method = RequestMethod.GET) public String view(Type type, Date beginDate, Date endDate, Model model) { if (type == null) { type = Type.month; } if (beginDate == null) { beginDate = DateUtils.addMonths(new Date(), -11); } if (endDate == null) { endDate = new Date(); } Map<Date, BigDecimal> salesAmountMap = new LinkedHashMap<Date, BigDecimal>(); Map<Date, Integer> salesVolumeMap = new LinkedHashMap<Date, Integer>(); Calendar beginCalendar = DateUtils.toCalendar(beginDate); Calendar endCalendar = DateUtils.toCalendar(endDate); int beginYear = beginCalendar.get(Calendar.YEAR); int endYear = endCalendar.get(Calendar.YEAR); int beginMonth = beginCalendar.get(Calendar.MONTH); int endMonth = endCalendar.get(Calendar.MONTH); for (int year = beginYear; year <= endYear; year++) { if (salesAmountMap.size() >= MAX_SIZE) { break; } Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.YEAR, year); if (type == Type.year) { calendar.set(Calendar.MONTH, calendar.getActualMinimum(Calendar.MONTH)); calendar.set(Calendar.DATE, calendar.getActualMinimum(Calendar.DATE)); calendar.set(Calendar.HOUR_OF_DAY, calendar.getActualMinimum(Calendar.HOUR_OF_DAY)); calendar.set(Calendar.MINUTE, calendar.getActualMinimum(Calendar.MINUTE)); calendar.set(Calendar.SECOND, calendar.getActualMinimum(Calendar.SECOND)); Date begin = calendar.getTime(); calendar.set(Calendar.MONTH, calendar.getActualMaximum(Calendar.MONTH)); calendar.set(Calendar.DATE, calendar.getActualMaximum(Calendar.DATE)); calendar.set(Calendar.HOUR_OF_DAY, calendar.getActualMaximum(Calendar.HOUR_OF_DAY)); calendar.set(Calendar.MINUTE, calendar.getActualMaximum(Calendar.MINUTE)); calendar.set(Calendar.SECOND, calendar.getActualMaximum(Calendar.SECOND)); Date end = calendar.getTime(); BigDecimal salesAmount = orderService.getSalesAmount(begin, end); Integer salesVolume = orderService.getSalesVolume(begin, end); salesAmountMap.put(begin, salesAmount != null ? salesAmount : BigDecimal.ZERO); salesVolumeMap.put(begin, salesVolume != null ? salesVolume : 0); } else { for (int month = year == beginYear ? beginMonth : calendar.getActualMinimum(Calendar.MONTH); month <= (year == endYear ? endMonth : calendar.getActualMaximum(Calendar.MONTH)); month++) { if (salesAmountMap.size() >= MAX_SIZE) { break; } calendar.set(Calendar.MONTH, month); calendar.set(Calendar.DATE, calendar.getActualMinimum(Calendar.DATE)); calendar.set(Calendar.HOUR_OF_DAY, calendar.getActualMinimum(Calendar.HOUR_OF_DAY)); calendar.set(Calendar.MINUTE, calendar.getActualMinimum(Calendar.MINUTE)); calendar.set(Calendar.SECOND, calendar.getActualMinimum(Calendar.SECOND)); Date begin = calendar.getTime(); calendar.set(Calendar.DATE, calendar.getActualMaximum(Calendar.DATE)); calendar.set(Calendar.HOUR_OF_DAY, calendar.getActualMaximum(Calendar.HOUR_OF_DAY)); calendar.set(Calendar.MINUTE, calendar.getActualMaximum(Calendar.MINUTE)); calendar.set(Calendar.SECOND, calendar.getActualMaximum(Calendar.SECOND)); Date end = calendar.getTime(); BigDecimal salesAmount = orderService.getSalesAmount(begin, end); Integer salesVolume = orderService.getSalesVolume(begin, end); salesAmountMap.put(begin, salesAmount != null ? salesAmount : BigDecimal.ZERO); salesVolumeMap.put(begin, salesVolume != null ? salesVolume : 0); } } } model.addAttribute("types", Type.values()); model.addAttribute("type", type); model.addAttribute("beginDate", beginDate); model.addAttribute("endDate", endDate); model.addAttribute("salesAmountMap", salesAmountMap); model.addAttribute("salesVolumeMap", salesVolumeMap); return "/admin/sales/view"; }
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 ww w. ja va 2 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:lineage2.gameserver.model.entity.events.impl.ClanHallAuctionEvent.java
/** * Method reCalcNextTime./*from w w w . j ava 2s. c o m*/ * @param onStart boolean */ @Override public void reCalcNextTime(boolean onStart) { clearActions(); _onTimeActions.clear(); Clan owner = getResidence().getOwner(); _endSiegeDate.setTimeInMillis(0); if ((getResidence().getAuctionLength() == 0) && (owner == null)) { getResidence().getSiegeDate().setTimeInMillis(System.currentTimeMillis()); getResidence().getSiegeDate().set(Calendar.DAY_OF_WEEK, Calendar.MONDAY); getResidence().getSiegeDate().set(Calendar.HOUR_OF_DAY, 15); getResidence().getSiegeDate().set(Calendar.MINUTE, 0); getResidence().getSiegeDate().set(Calendar.SECOND, 0); getResidence().getSiegeDate().set(Calendar.MILLISECOND, 0); getResidence().setAuctionLength(7); getResidence().setAuctionMinBid(getResidence().getBaseMinBid()); getResidence().setJdbcState(JdbcEntityState.UPDATED); getResidence().update(); _onTimeActions.clear(); addOnTimeAction(0, new StartStopAction(EVENT, true)); addOnTimeAction(getResidence().getAuctionLength() * 86400, new StartStopAction(EVENT, false)); _endSiegeDate.setTimeInMillis(getResidence().getSiegeDate().getTimeInMillis() + (getResidence().getAuctionLength() * 86400000L)); registerActions(); } else if ((getResidence().getAuctionLength() == 0) && (owner != null)) { } else { long endDate = getResidence().getSiegeDate().getTimeInMillis() + (getResidence().getAuctionLength() * 86400000L); if (endDate <= System.currentTimeMillis()) { getResidence().getSiegeDate().setTimeInMillis(System.currentTimeMillis()); } _endSiegeDate.setTimeInMillis(getResidence().getSiegeDate().getTimeInMillis() + (getResidence().getAuctionLength() * 86400000L)); _onTimeActions.clear(); addOnTimeAction(0, new StartStopAction(EVENT, true)); addOnTimeAction(getResidence().getAuctionLength() * 86400, new StartStopAction(EVENT, false)); registerActions(); } }
From source file:TimeUtils.java
public static synchronized StringBuffer appendTime(StringBuffer sb, long timeStamp, boolean millisecond) { if (timeStamp == 0) { sb.append("n/a"); return sb; }// w w w . ja v a 2 s. c o m if (singleCalendar == null) { singleCalendar = Calendar.getInstance(); singleDate = new Date(); } singleDate.setTime(timeStamp); singleCalendar.setTime(singleDate); StringUtils.appendD00(sb, singleCalendar.get(Calendar.HOUR_OF_DAY)).append(':'); StringUtils.appendD00(sb, singleCalendar.get(Calendar.MINUTE)).append(':'); StringUtils.appendD00(sb, singleCalendar.get(Calendar.SECOND)); if (millisecond) { sb.append('.'); StringUtils.appendD000(sb, singleCalendar.get(Calendar.MILLISECOND)); } return sb; }
From source file:com.aimdek.ccm.dao.impl.test.StatementDaoImplTest.java
/** * Initialize.//from w w w . j a va 2s . c o m */ @Before public void initialize() { List<Statement> statementList = new ArrayList<Statement>(); Statement statement = new Statement(); statement.setAmountDue(500); statement.setCardNumber("1234-1234-1234-0008"); Calendar calendar1 = Calendar.getInstance(); calendar1.setTime(new Date()); calendar1.add(Calendar.DATE, 15); calendar1.set(Calendar.HOUR_OF_DAY, 23); calendar1.set(Calendar.MINUTE, 59); calendar1.set(Calendar.MINUTE, 59); statement.setDueDate(calendar1.getTime()); statement.setStatementDate(new Date()); Calendar calendar = Calendar.getInstance(); calendar = Calendar.getInstance(); calendar.add(Calendar.DAY_OF_MONTH, -1); calendar.set(Calendar.HOUR_OF_DAY, 23); calendar.set(Calendar.MINUTE, 59); calendar.set(Calendar.SECOND, 59); statement.setToDate(calendar.getTime()); statement.setCreditCardId(1); statementList.add(statement); Statement statement1 = new Statement(); statement1.setAmountDue(500); statement1.setCardNumber("1234-1234-1234-0008"); statement1.setDueDate(calendar1.getTime()); statement1.setStatementDate(new Date()); statement1.setToDate(calendar.getTime()); statement1.setCreditCardId(2); statement1.setStatementDate(new Date()); statementList.add(statement1); Statement statement2 = new Statement(); statement2.setAmountDue(500); statement2.setCardNumber("1234-1234-1234-0008"); statement2.setDueDate(calendar1.getTime()); statement2.setStatementDate(new Date()); statement2.setToDate(calendar.getTime()); statement2.setCreditCardId(3); statement2.setStatementDate(new Date()); statementList.add(statement2); Statement statement3 = new Statement(); statement3.setAmountDue(500); statement3.setCardNumber("1234-1234-1234-0008"); statement3.setDueDate(calendar1.getTime()); statement3.setStatementDate(new Date()); statement3.setToDate(calendar.getTime()); statement3.setCreditCardId(3); statement3.setStatementDate(new Date()); statementList.add(statement3); statementRepository.save(statementList); }