List of usage examples for org.apache.commons.lang3.time DateFormatUtils format
public static String format(final Calendar calendar, final String pattern)
Formats a calendar into a specific pattern.
From source file:com.glaf.core.web.servlet.FileUploadServlet.java
public void upload(HttpServletRequest request, HttpServletResponse response) { response.setContentType("text/html;charset=UTF-8"); LoginContext loginContext = RequestUtils.getLoginContext(request); if (loginContext == null) { return;/*from w w w .j a va 2s .c om*/ } String serviceKey = request.getParameter("serviceKey"); String type = request.getParameter("type"); if (StringUtils.isEmpty(type)) { type = "0"; } Map<String, Object> paramMap = RequestUtils.getParameterMap(request); logger.debug("paramMap:" + paramMap); String rootDir = SystemProperties.getConfigRootPath(); InputStream inputStream = null; try { DiskFileItemFactory diskFactory = new DiskFileItemFactory(); // threshold ???? 8M diskFactory.setSizeThreshold(8 * FileUtils.MB_SIZE); // repository diskFactory.setRepository(new File(rootDir + "/temp")); ServletFileUpload upload = new ServletFileUpload(diskFactory); int maxUploadSize = conf.getInt(serviceKey + ".maxUploadSize", 0); if (maxUploadSize == 0) { maxUploadSize = conf.getInt("upload.maxUploadSize", 50);// 50MB } maxUploadSize = maxUploadSize * FileUtils.MB_SIZE; logger.debug("maxUploadSize:" + maxUploadSize); upload.setHeaderEncoding("UTF-8"); upload.setSizeMax(maxUploadSize); upload.setFileSizeMax(maxUploadSize); String uploadDir = Constants.UPLOAD_PATH; if (ServletFileUpload.isMultipartContent(request)) { logger.debug("#################start upload process#########################"); FileItemIterator iter = upload.getItemIterator(request); PrintWriter out = response.getWriter(); while (iter.hasNext()) { FileItemStream item = iter.next(); if (!item.isFormField()) { // ???? String autoCreatedDateDirByParttern = "yyyy/MM/dd"; String autoCreatedDateDir = DateFormatUtils.format(new java.util.Date(), autoCreatedDateDirByParttern); File savePath = new File(rootDir + uploadDir + autoCreatedDateDir); if (!savePath.exists()) { savePath.mkdirs(); } String fileId = UUID32.getUUID(); String fileName = savePath + "/" + fileId; BlobItem dataFile = new BlobItemEntity(); dataFile.setLastModified(System.currentTimeMillis()); dataFile.setCreateBy(loginContext.getActorId()); dataFile.setFileId(fileId); dataFile.setPath(uploadDir + autoCreatedDateDir + "/" + fileId); dataFile.setFilename(item.getName()); dataFile.setName(item.getName()); dataFile.setContentType(item.getContentType()); dataFile.setType(type); dataFile.setStatus(0); dataFile.setServiceKey(serviceKey); getBlobService().insertBlob(dataFile); inputStream = item.openStream(); FileUtils.save(fileName, inputStream); logger.debug(fileName + " save ok."); out.print(fileId); } } } } catch (Exception ex) { ex.printStackTrace(); } finally { IOUtils.close(inputStream); } }
From source file:cn.mypandora.util.MyDateUtils.java
/** * ?// w ww.j a v a2 s .c o m * * @return */ public static String getCurrentTime() { Calendar cal = Calendar.getInstance(); String currentDate = DateFormatUtils.format(cal, TIME_FORMAT); return currentDate; }
From source file:cn.org.awcp.core.utils.DateUtils.java
/** * ?<br>/* w w w .j av a2 s . c om*/ * generate by: vakin jiang at 2012-3-7 * * @param orig * @param patterns * @return */ public static String format(Date date, String... patterns) { if (date == null) return ""; String pattern = YYYY_MM_DD_HH_MM_SS; if (patterns != null && patterns.length > 0 && StringUtils.isNotBlank(patterns[0])) { pattern = patterns[0]; } return DateFormatUtils.format(date, pattern); }
From source file:cn.guoyukun.spring.web.upload.FileUploadUtils.java
/** * ?// 2013/01/03/*from w w w.j a va2 s .c om*/ * * @return */ private static final String datePath() { Date now = new Date(); return DateFormatUtils.format(now, "yyyy/MM/dd"); }
From source file:cn.mypandora.util.MyDateUtils.java
/** * ??/* w ww .j a v a 2 s .c o m*/ * * @return */ public static String getPreviousMonthDate() { Calendar calendar = Calendar.getInstance(); calendar.add(Calendar.DATE, -1); // ? calendar.add(Calendar.MONTH, -1); // ? String currentDate = DateFormatUtils.format(calendar, DATE_FORMAT); return currentDate; }
From source file:com.netsteadfast.greenstep.bsc.service.impl.MonitorItemScoreServiceImpl.java
@Override public Map<String, List<MonitorItemScoreVO>> getHistoryDataList(String itemType, String frequency, String dateVal, String orgId, String empId, int daysBeforeRange) throws ServiceException, Exception { if (StringUtils.isBlank(itemType) || StringUtils.isBlank(frequency) || StringUtils.isBlank(dateVal)) { throw new ServiceException(SysMessageUtil.get(GreenStepSysMsgConstants.PARAMS_BLANK)); }//from ww w . j av a 2 s .co m if (!SimpleUtils.isDate(dateVal)) { throw new ServiceException(SysMessageUtil.get(GreenStepSysMsgConstants.PARAMS_INCORRECT)); } if (daysBeforeRange > MAX_DAYS_BEFORE_RANGE || daysBeforeRange < 0) { throw new ServiceException("daysBeforeRange error!"); } Date endDate = DateUtils.parseDate(dateVal, new String[] { "yyyyMMdd" }); Date startDate = DateUtils.addDays(endDate, (daysBeforeRange * -1)); String startDateStr = DateFormatUtils.format(startDate, "yyyyMMdd"); Map<String, Object> paramMap = new HashMap<String, Object>(); paramMap.put("itemType", itemType); paramMap.put("frequency", frequency); paramMap.put("orgId", orgId); paramMap.put("empId", empId); Map<String, CustomeOperational> customeMap = new HashMap<String, CustomeOperational>(); CustomeOperational op1 = new CustomeOperational(); op1.setField("dateVal"); op1.setOp(">="); op1.setValue(startDateStr); CustomeOperational op2 = new CustomeOperational(); op2.setField("dateVal"); op2.setOp("<="); op2.setValue(dateVal); customeMap.put("op1", op1); customeMap.put("op2", op2); List<BbMonitorItemScore> searchList = this.findListByParams2(paramMap, customeMap); if (null == searchList || searchList.size() < 1) { return null; } Map<String, List<MonitorItemScoreVO>> dataMap = new HashMap<String, List<MonitorItemScoreVO>>(); List<String> idKeyList = new ArrayList<String>(); for (BbMonitorItemScore data : searchList) { if (idKeyList.contains(data.getItemId())) { continue; } idKeyList.add(data.getItemId()); dataMap.put(data.getItemId(), new LinkedList<MonitorItemScoreVO>()); } for (int i = 0; i <= daysBeforeRange; i++) { Date currentDate = DateUtils.addDays(startDate, i); String currentDateStr = DateFormatUtils.format(currentDate, "yyyyMMdd"); for (String id : idKeyList) { MonitorItemScoreVO scoreData = new MonitorItemScoreVO(); scoreData.setItemType(itemType); scoreData.setItemId(id); scoreData.setFrequency(frequency); scoreData.setOrgId(orgId); scoreData.setEmpId(empId); scoreData.setDateVal(currentDateStr); scoreData.setScore("0"); // ?, ?"0" for (BbMonitorItemScore data : searchList) { if (data.getItemId().equals(id) && data.getDateVal().equals(currentDateStr)) { scoreData.setScore(data.getScore()); } } dataMap.get(id).add(scoreData); } } return dataMap; }
From source file:cn.org.awcp.core.utils.DateUtils.java
/** * ??<br>//w ww .j a v a 2s . c o m * generate by: vakin jiang at 2012-3-7 * * @param orig * @param patterns * @return */ public static Date formatDate(Date orig, String... patterns) { String pattern = YYYY_MM_DD_HH_MM_SS; if (patterns != null && patterns.length > 0 && StringUtils.isNotBlank(patterns[0])) { pattern = patterns[0]; } return parseDate(DateFormatUtils.format(orig, pattern)); }
From source file:cn.mypandora.util.MyDateUtils.java
/** * ????X/* w ww . j av a 2 s . c o m*/ * * @param offset * @return */ public static String getOffsetDate(int offset) { Calendar cal = Calendar.getInstance(); cal.add(Calendar.DAY_OF_MONTH, offset); String currentDate = DateFormatUtils.format(cal, DATE_FORMAT); return currentDate; }
From source file:cn.mypandora.util.MyDateUtils.java
/** * ???X/*from w ww . j ava2 s . c o m*/ * * @param specifiedDate ,?YYYY-MM-DD * @param offset ?? * @return * @throws ParseException */ public static String getSpecifiedOffsetDate(String specifiedDate, int offset) throws ParseException { Date date = DateUtils.parseDate(specifiedDate, DATE_FORMAT); Calendar cal = DateUtils.toCalendar(date); cal.add(Calendar.DAY_OF_MONTH, offset); String returnDate = DateFormatUtils.format(cal, DATE_FORMAT); return returnDate; }
From source file:com.hbc.api.fund.biz.service.MISFundWithdrawService.java
@Transactional public String tryToTransfer(List<TransInfo> batchTransferList, Double totalAmount, Date transTime, String optId, String optName, String pattern) { if (batchTransferList == null || batchTransferList.size() <= 0) { return ""; }//from w w w . jav a 2s . co m logger.info("??|??->{} ?->{}", batchTransferList, totalAmount); String batchNo = IDGenerotor.generateFundWithDrawNo(); Iterator<TransInfo> transInfoIterator = batchTransferList.iterator(); while (transInfoIterator.hasNext()) { TransInfo transInfo = transInfoIterator.next(); // TODO ???? FundWithdrawPaymentExample example = new FundWithdrawPaymentExample(); example.createCriteria().andDrawNoEqualTo(transInfo.getTransNo()); List<FundWithdrawPayment> payments = fundWithdrawPaymentMapper.selectByExample(example); if (payments != null && payments.size() > 0) { Iterator<FundWithdrawPayment> paymentsIterator = payments.iterator(); while (paymentsIterator.hasNext()) { FundWithdrawPayment fundWithdrawPayment = paymentsIterator.next(); // ? 0? | 1?? | 2? | 3 Integer transStatus = fundWithdrawPayment.getTransferStatus(); if (transStatus == FundDrawPaymentStatus.PAYMENT_SUCCESS.value) { throw new FundException(FundReturnCodeEnum.ERR_UPDATE, "??[" + fundWithdrawPayment.getDrawNo() + "] ????."); } } } FundWithdrawPayment payment = new FundWithdrawPayment(); String paymentId = IDGenerotor.generatePaymentId(); Date currentDate = new Date(); payment.setPaymentId(paymentId); payment.setBatchNo(batchNo); payment.setDrawNo(transInfo.getTransNo()); payment.setCreateTime(currentDate); payment.setGuideId(transInfo.getGuideId() == null ? "" : transInfo.getGuideId()); payment.setOperatorId(optId); payment.setOperatorName(optName); payment.setPayeeAccount(transInfo.getPayeeAccount()); payment.setPayeeName(transInfo.getPayeeName()); payment.setPayerAccount(alipayConfig.sellerEmail); payment.setPaymentMethod(FundBankCardType.ALIPAY.value); payment.setActualAmount(transInfo.getActualAmount()); payment.setTransferAmount(transInfo.getTransAmount()); payment.setTransferDatetime(transTime); payment.setTransferStatus(FundDrawPaymentStatus.PAYMENT_INIT.value); final String remark = "[" + currentDate + "] - ?[" + optId + "(" + optName + ")" + "] ??(?):[" + transInfo.getActualAmount() + "]:[" + transInfo.getPayeeAccount() + "],?:[" + batchNo + "],??:[" + transInfo.getTransNo() + "]"; payment.setRemark(remark); logger.info("??|??-> {}", payment); fundWithdrawPaymentMapper.insert(payment); FundWithdrawal fundWithdrawal = fundWithdrawMapper.selectByPrimaryKey(transInfo.getTransNo()); if (fundWithdrawal == null) { logger.error("?? {} ???", transInfo.getTransNo()); throw new FundException(FundReturnCodeEnum.ERR_UPDATE, "???"); } Integer oldDrawStatus = fundWithdrawal.getDrawStatus(); if (oldDrawStatus == FundDrawStatus.AUTO_WITHDRAW_APPLIED.value) { logger.error("??|?"); throw new FundException(FundReturnCodeEnum.ERR_UPDATE, "?"); } FundWithdrawalExample criteria = new FundWithdrawalExample(); criteria.createCriteria().andDrawNoEqualTo(transInfo.getTransNo()); fundWithdrawal.setDrawStatus(FundDrawStatus.AUTO_WITHDRAW_APPLIED.value); fundWithdrawal.setUpdateTime(currentDate); fundWithdrawal.setAccount(transInfo.getActualAccount()); fundWithdrawal.setDrawComment( StringUtils.isNoneBlank(fundWithdrawal.getDrawComment()) ? fundWithdrawal.getDrawComment() : "" + "->" + transInfo.getActualRemark() + "BY:" + optId + " " + optName); logger.info("??|??-> {} | ??: {} -> {}", fundWithdrawal, FundDrawStatus.getStatus(oldDrawStatus), FundDrawStatus.getStatus(fundWithdrawal.getDrawStatus())); fundWithdrawMapper.updateByExampleSelective(fundWithdrawal, criteria); } String aliDate = DateFormatUtils.format(transTime, pattern); String returnUrl = gAliTransPayService.getFundTransferUrl(batchNo, batchTransferList, totalAmount, aliDate); return returnUrl; }