List of usage examples for java.util Calendar getTimeInMillis
public long getTimeInMillis()
From source file:gov.nih.nci.cacisweb.user.CacisUserService.java
@Override public UserDetails loadUserByUsername(String arg0) throws UsernameNotFoundException { try {/* w ww. j a v a 2 s.c om*/ log.debug("Loading User.."); String userProperty = CaCISUtil.getProperty(arg0); if (userProperty == null) { log.error("User Not Found"); throw new UsernameNotFoundException("User Not Found"); } String[] userDetails = StringUtils.splitPreserveAllTokens(userProperty, ','); if (userDetails.length > 0 && userDetails.length < 5) { log.error("User Not Configured Properly"); throw new UsernameNotFoundException("User Not Configured Properly"); } Collection<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>(); int i = 4; while (i < userDetails.length) { authorities.add(new SimpleGrantedAuthority(userDetails[i])); i++; } SimpleDateFormat sDateFormat = new SimpleDateFormat(CaCISWebConstants.COM_DATE_FORMAT); if (!StringUtils.isBlank(userDetails[3])) { Calendar lockOutTimeCalendar = Calendar.getInstance(); lockOutTimeCalendar.setTime(sDateFormat.parse(userDetails[3])); long lockoutTimeMillis = lockOutTimeCalendar.getTimeInMillis(); long currentTimeMillis = Calendar.getInstance().getTimeInMillis(); long diffMinutes = (currentTimeMillis - lockoutTimeMillis) / (1000 * 60); if (diffMinutes > 60) { log.debug("Lockout Time greater than restricted time. Hence unlocking"); return new CacisUser(arg0, userDetails[0], true, new Short("0").shortValue(), "", authorities); } } return new CacisUser(arg0, userDetails[0], new Boolean(userDetails[1]).booleanValue(), new Short(userDetails[2]).shortValue(), userDetails[3], authorities); } catch (CaCISWebException e) { log.error("User Not Found... " + e.getMessage()); throw new UsernameNotFoundException("User Not Found. " + e.getMessage()); } catch (ParseException e) { log.error("Lockout time not configured properly. " + e.getMessage()); throw new UsernameNotFoundException("Lockout time not configured properly. " + e.getMessage()); } }
From source file:ch.cyberduck.core.openstack.SwiftUrlProvider.java
protected long getExpiry(final int seconds) { final Calendar expiry = Calendar.getInstance(TimeZone.getTimeZone("UTC")); expiry.add(Calendar.SECOND, seconds); return expiry.getTimeInMillis() / 1000; }
From source file:gxu.software_engineering.shen10.market.service.ItemServiceTest.java
@Test public void testSync() { Calendar c = Calendar.getInstance(); c.set(2013, Calendar.JUNE, 24); List<Item> items = itemService.sync(c.getTimeInMillis(), 50); System.err.println(items.size()); assertThat(items.size() > 1, is(true)); }
From source file:info.raack.appliancelabeler.machinelearning.appliancedetection.algorithms.ApplianceEnergyConsumptionDetectionAlgorithm.java
protected Queue<EnergyTimestep> getEnergyTimesteps(Calendar firstMeasurementDate, Calendar lastMeasurementDate) { Queue<EnergyTimestep> timesteps = new LinkedBlockingQueue<EnergyTimestep>(); Calendar startDate = dateUtils.getPreviousFiveMinuteIncrement(firstMeasurementDate); Calendar endDate = dateUtils.getPreviousFiveMinuteIncrement(lastMeasurementDate); while (startDate.getTimeInMillis() < endDate.getTimeInMillis()) { EnergyTimestep timestep = new EnergyTimestep(); timestep.setStartTime(startDate.getTime()); startDate.add(Calendar.MINUTE, 5); startDate.add(Calendar.SECOND, -1); timestep.setEndTime(startDate.getTime()); startDate.add(Calendar.SECOND, 1); //logger.debug("Adding timestep " + timestep.getStartTime() + " - " + timestep.getEndTime()); timesteps.add(timestep);/*from w w w . ja va 2 s . co m*/ } return timesteps; }
From source file:com.dianping.lion.db.DataSourceJob.java
@Override public void doBusiness() throws Exception { JobExecTime jobExecTime = jobExecTimeDao.getJobExecTime(jobName); Calendar can = Calendar.getInstance(); can.setTime(jobExecTime.getLastFetchTime()); String dsContent = dataSourceFetcher.fetchDS(can.getTimeInMillis() / 1000); if (StringUtils.isBlank(dsContent)) { return;/*from w w w. j a va 2 s . c o m*/ } try { try { User user = userService.findById(ServiceConstants.USER_SA_ID); SecurityUtils.setCurrentUser(user); storager.store(dsContent); jobExecTime .setLastFetchTime(new Date(Long.parseLong(jsonParser.getLastFetchTime(dsContent)) * 1000)); jobExecTimeDao.updateLastFetchTime(jobExecTime); operationLogService .createOpLog(new OperationLog(OperationTypeEnum.Job_DSFetcher, "???.") .key(null, null, dsContent)); } finally { SecurityUtils.clearCurrentUser(); } } catch (Exception e) { logger.debug("Failed to store the config.", e); if (jobExecTime.getFailMail() != null && (count % alarmthreshold == 0)) { String[] mails = jobExecTime.getFailMail().split(","); StringWriter out = new StringWriter(); e.printStackTrace(new PrintWriter(out)); for (String email : mails) { StringBuffer body = new StringBuffer(); body.append("" + jobExecTime.getLastFetchTime() + "?DB?:\n" + dsContent); body.append("\n?->\n" + out.toString()); boolean emailSendResult = mailService.send(mailCode, email, title, body.toString()); if (!emailSendResult) { logger.warn("Send mail Fail!Email Address:" + email); } } } count++; } logger.debug("running"); }
From source file:com.datatorrent.flume.source.HdfsTestSource.java
public HdfsTestSource() { super();/*from w ww. j av a 2 s . c om*/ this.rate = 2500; dataFiles = Lists.newArrayList(); Calendar calendar = Calendar.getInstance(); calendar.add(Calendar.DATE, -1); oneDayBack = calendar.getTimeInMillis(); configuration = new Configuration(); events = Lists.newArrayList(); }
From source file:free.yhc.feeder.model.Utils.java
/** * Get time milliseconds at 00:00:00(hh:mm:ss) of given day. * For example, calling function with argument "2012-12-25, 13:46:57" calendar value, * gives time milliseconds of "2012-12-25, 00:00:00". * @param cal/*from w w w. j a v a 2 s.c o m*/ * @return */ public static long dayBaseMs(Calendar cal) { Calendar temp = Calendar.getInstance(); temp.setTime(cal.getTime()); // Set to 00:00:00:000 temp.set(Calendar.HOUR_OF_DAY, 0); temp.set(Calendar.MINUTE, 0); temp.set(Calendar.SECOND, 0); temp.set(Calendar.MILLISECOND, 0); return temp.getTimeInMillis(); }
From source file:controller.PaymentController.java
@RequestMapping(value = "/process", method = RequestMethod.GET) public ModelAndView processPayment(Authentication authen, HttpServletRequest req, @RequestParam int month) { ModelAndView model = new ModelAndView(); try {//ww w . ja v a 2 s. com model.setViewName("processPayment"); Customer cus = cusModel.find(authen.getName(), "username", false).get(0); int orderID = orderModel.getOrderIDByCustomerNonActive(cus.getCustomerId()); int orderIDActive = orderModel.getOrderIDByCustomer(cus.getCustomerId()); Order order = orderModel.getByID(orderID); Order orderActive = orderModel.getByID(orderIDActive); if (order.getStatus() == 1) { order.setOderId(0); Calendar ca = Calendar.getInstance(); ca.setTime(orderActive.getOrderExpiredDate()); ca.add(Calendar.MONTH, month); order.setOrderExpiredDate(new Date(ca.getTimeInMillis())); } else { Calendar ca = Calendar.getInstance(); ca.setTime(orderActive.getOrderExpiredDate()); ca.add(Calendar.MONTH, month); order.setOrderExpiredDate(ca.getTime()); } order.setOrderPaymentDate(new Date()); order.setStatus((byte) 0); Set<OderDetail> listOrderDetail = order.getOderDetails(); orderModel.addOrUpdate(order); for (OderDetail orderdetail : listOrderDetail) { orderdetail.setId(new OderDetailId(order.getOderId(), orderdetail.getId().getPackageId())); } model.addObject("check", orderModel.addOrUpdate(order)); model.addObject("alert", "Send request success"); model.addObject("link", req.getContextPath() + "/index.html"); } catch (Exception ex) { ex.printStackTrace(); model.addObject("alert", "Error: " + ex.getMessage()); } return model; }
From source file:com.hihframework.core.utils.DateUtils.java
/** * ??/* www . j a va2 s . com*/ * * @return */ public static long getNowDateTimeLong() { Calendar cal = Calendar.getInstance(); return cal.getTimeInMillis(); }
From source file:net.duckling.ddl.service.share.impl.ShareFileAccessServiceImpl.java
@Override public String getRestOfVaildDays(ShareFileAccess s) { Calendar c = Calendar.getInstance(); c.setTime(s.getCreateTime());//from w ww. j a v a 2 s. c om c.add(Calendar.DATE, s.getValidOfDays()); Date now = new Date(); return AoneTimeUtils.getLastTime(c.getTimeInMillis() - now.getTime()); }