當前位置: 首頁>>代碼示例>>Java>>正文


Java DateFormatUtils.format方法代碼示例

本文整理匯總了Java中org.apache.commons.lang3.time.DateFormatUtils.format方法的典型用法代碼示例。如果您正苦於以下問題:Java DateFormatUtils.format方法的具體用法?Java DateFormatUtils.format怎麽用?Java DateFormatUtils.format使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.commons.lang3.time.DateFormatUtils的用法示例。


在下文中一共展示了DateFormatUtils.format方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: genHTML

import org.apache.commons.lang3.time.DateFormatUtils; //導入方法依賴的package包/類
/**
	 * Processes the specified FreeMarker template with the specified request,
	 * data model.
	 *
	 * @param request
	 *            the specified request
	 * @param dataModel
	 *            the specified data model
	 * @param template
	 *            the specified FreeMarker template
	 * @return generated HTML
	 * @throws Exception
	 *             exception
	 */
	protected String genHTML(final HttpServletRequest request, final Map<String, Object> dataModel,
			final Template template) throws Exception {
		final StringWriter stringWriter = new StringWriter();

		template.setOutputEncoding("UTF-8");
		template.process(dataModel, stringWriter);

		final StringBuilder pageContentBuilder = new StringBuilder(stringWriter.toString());

		final long endimeMillis = System.currentTimeMillis();
		final String dateString = DateFormatUtils.format(endimeMillis, "yyyy/MM/dd HH:mm:ss");
//		final long startTimeMillis = (Long) request.getAttribute(Keys.HttpRequest.START_TIME_MILLIS);
		final long startTimeMillis = System.currentTimeMillis();
		final String msg = String.format("<!-- Generated by B3log Latke(%1$d ms), %2$s -->",
				endimeMillis - startTimeMillis, dateString);

		pageContentBuilder.append(msg);

		return pageContentBuilder.toString();
	}
 
開發者ID:daima,項目名稱:solo-spring,代碼行數:35,代碼來源:AbstractFreeMarkerRenderer.java

示例2: getMonthLastDay

import org.apache.commons.lang3.time.DateFormatUtils; //導入方法依賴的package包/類
/** 
 * @Title:getMonthLastDay 
 * @Description: 得到當前月最後一天 
 * @return 
 * @return String 
 */  
public static String getMonthLastDay() {  
    Calendar cal = Calendar.getInstance();  
    Calendar f = (Calendar) cal.clone();  
    f.clear();  
    // 方法一  
    // f.set(Calendar.YEAR, cal.get(Calendar.YEAR));  
    // f.set(Calendar.MONTH, cal.get(Calendar.MONTH) + 1);  
    // f.set(Calendar.MILLISECOND, -1);  
    // return DateFormatUtils.format(f, DATE_FORMAT);  
  
    // 方法二  
    // f.set(Calendar.YEAR, cal.get(Calendar.YEAR));  
    // f.set(Calendar.MONTH, cal.get(Calendar.MONTH));  
    // f.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DATE));  
    // return DateFormatUtils.format(f, DATE_FORMAT);  
  
    // 方法三(同一)  
    cal.set(Calendar.DATE, 1);// 設為當前月的1號  
    cal.add(Calendar.MONTH, 1);// 加一個月,變為下月的1號  
    cal.add(Calendar.DATE, -1);// 減去一天,變為當月最後一天  
    return DateFormatUtils.format(cal, DATE_FORMAT);  
}
 
開發者ID:phoenix2014,項目名稱:rexxar,代碼行數:29,代碼來源:RexxarDateUtils.java

示例3: WXPayInit

import org.apache.commons.lang3.time.DateFormatUtils; //導入方法依賴的package包/類
public void WXPayInit() {
	// 讀取 resources 文件
	String filePath = System.getProperty("user.dir") + "/rootca.pem";
	WXPay.initSDKConfiguration("YIyqXSZ37xWFsIVDJ86V2uUL1Ly0Gz80", "wxae6a7f991c35cb0d", "1307253101", "", filePath,
			"1307253101");
	System.out.println("CertLocalPath:" + filePath);
	System.out.println(RandomStringUtils.randomNumeric(32));
	ScanPayReqData scanPayReqData = new ScanPayReqData("123123123", "商品測試", "attach",
			RandomStringUtils.randomNumeric(32), 1, "test", "127.0.0.1",
			DateFormatUtils.format(new Date(), "yyyyMMddHHmmss"),
			DateFormatUtils.format(new Date(), "yyyyMMddHHmmss"), "test");
	try {
		String info = WXPay.requestScanPayService(scanPayReqData);
		System.out.println(info);
	} catch (Exception e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	Assert.assertNotNull(WXPay.class);
}
 
開發者ID:mallog,項目名稱:mohoo-wechat-pay,代碼行數:21,代碼來源:WXPayTest.java

示例4: getNextMonthFirst

import org.apache.commons.lang3.time.DateFormatUtils; //導入方法依賴的package包/類
/** 
 * @Title:getNextMonthFirst 
 * @Description: 得到下個月的第一天 
 * @return 
 * @return String 
 */  
public static String getNextMonthFirst() {  
    Calendar cal = Calendar.getInstance();  
    Calendar f = (Calendar) cal.clone();  
    f.clear();  
    // 方法一  
    // f.set(Calendar.YEAR, cal.get(Calendar.YEAR));  
    // f.set(Calendar.MONTH, cal.get(Calendar.MONTH) + 1);  
    // f.set(Calendar.DATE, 1);  
    // or f.set(Calendar.DAY_OF_MONTH,cal.getActualMinimum(Calendar.DATE));  
    // return DateFormatUtils.format(f, DATE_FORMAT);  
  
    // 方法二  
    cal.set(Calendar.DATE, 1);// 設為當前月的1號  
    cal.add(Calendar.MONTH, +1);// 加一個月,變為下月的1號  
    return DateFormatUtils.format(cal, DATE_FORMAT);  
}
 
開發者ID:phoenix2014,項目名稱:rexxar,代碼行數:23,代碼來源:RexxarDateUtils.java

示例5: backup

import org.apache.commons.lang3.time.DateFormatUtils; //導入方法依賴的package包/類
public static String backup(String origFileName) throws IOException {

		// Get backup file name by inserting timestamp before extension name.
		String timestamp = DateFormatUtils.format(Calendar.getInstance().getTime(), "[yyyy.MM.dd'T'HH.mm.ss]");
		int lastIdxOfDot = origFileName.lastIndexOf(".");
		String backupFileName = origFileName.substring(0, lastIdxOfDot + 1) + timestamp + origFileName.substring(lastIdxOfDot, origFileName.length());

		// Create backup file by renaming original file.
		File origFile = new File(origFileName);
		File backFile = new File(backupFileName);

		logger.info("BACKUP: Begin to make a backup for file: " + origFileName);
		FileUtils.copyFile(origFile, backFile);

		return backupFileName;

	}
 
開發者ID:ourbeehive,項目名稱:MyBatisPioneer,代碼行數:18,代碼來源:FileHandler.java

示例6: getLineChartCategories

import org.apache.commons.lang3.time.DateFormatUtils; //導入方法依賴的package包/類
public static List<String> getLineChartCategories(String dateVal, int dataSize) throws Exception {
	List<String> categories = new LinkedList<String>();
	if (dataSize < 0) {
		throw new ServiceException("data-size error!");
	}		
	Date endDate = DateUtils.parseDate(dateVal, new String[]{"yyyyMMdd"});
	int dateRange = dataSize -1;
	if (dateRange < 0) {
		dateRange = 0;
	}
	if (dateRange == 0) {
		categories.add( DateFormatUtils.format(endDate, "yyyy/MM/dd") );
		return categories;
	}
	Date startDate = DateUtils.addDays(endDate, (dateRange * -1) );
	for (int i=0; i<dataSize; i++) {
		Date currentDate = DateUtils.addDays(startDate, i);
		String currentDateStr = DateFormatUtils.format(currentDate, "yyyy/MM/dd");
		categories.add(currentDateStr);
	}
	return categories;
}
 
開發者ID:billchen198318,項目名稱:bamboobsc,代碼行數:23,代碼來源:HistoryItemScoreReportContentQueryUtils.java

示例7: parsePayload

import org.apache.commons.lang3.time.DateFormatUtils; //導入方法依賴的package包/類
private void parsePayload(Element payloadElement) {
  if(payloadElement != null) {
    Document d = payloadElement.getDocument();
    Node mmxPayloadNode = d.selectSingleNode(String.format("/*[name()='%s']/*[name()='%s']", Constants.MMX_ELEMENT, Constants.MMX_PAYLOAD));

    if(mmxPayloadNode != null) {
      String mtype = mmxPayloadNode.valueOf("@mtype");
      String stamp = DateFormatUtils.format(new DateTime(mmxPayloadNode.valueOf("@stamp")).toDate(), "yyyy-MM-dd'T'HH:mm:ss'Z'", TimeZone.getTimeZone("UTC"));
      String data = mmxPayloadNode.getText();
      payload = new MMXPubSubPayload(mtype, stamp, data);
    }

    Node mmxMetaNode = d.selectSingleNode(String.format("/*[name()='%s']/*[name()='%s']", Constants.MMX_ELEMENT, Constants.MMX_META));

    if(mmxMetaNode != null) {
      meta = getMapFromJsonString(mmxMetaNode.getText());
    }
  }
}
 
開發者ID:magnetsystems,項目名稱:message-server,代碼行數:20,代碼來源:MMXPubSubItemChannel.java

示例8: onMesg

import org.apache.commons.lang3.time.DateFormatUtils; //導入方法依賴的package包/類
/**
 * This just pulls a handful of values from the session for illustration purposes.
 * @param sessionMesg
 */
@Override
public void onMesg(SessionMesg sessionMesg) {
    if (sessionMesg.getTotalDistance() != null) {
        fitActivity.setTotalMeters(sessionMesg.getTotalDistance().doubleValue());
    }
    if (sessionMesg.getStartTime() != null) {
        final String formatedDate = DateFormatUtils.format( sessionMesg.getStartTime().getDate(), "yyyy-MM-dd'T'HH:mm'Z'", TimeZone.getTimeZone("UTC"));
        fitActivity.setStartTime(formatedDate);
    }
    if (sessionMesg.getTotalTimerTime() != null) {
        fitActivity.setTotalSeconds(sessionMesg.getTotalTimerTime().doubleValue());
    }
    if (sessionMesg.getSport() != null) {
        fitActivity.setSport(sessionMesg.getSport().name());
    }
}
 
開發者ID:smitchell,項目名稱:garmin-fit-geojson,代碼行數:21,代碼來源:GarminFitListener.java

示例9: getStringRepOfFieldValueForInsert

import org.apache.commons.lang3.time.DateFormatUtils; //導入方法依賴的package包/類
protected static String getStringRepOfFieldValueForInsert(Field field) {
  switch (field.getType()) {
    case BYTE_ARRAY:
      //Do a hex encode.
      return Hex.encodeHexString(field.getValueAsByteArray());
    case BYTE:
      return String.valueOf(field.getValueAsInteger());
    case TIME:
      return DateFormatUtils.format(field.getValueAsDate(), "HH:mm:ss.SSS");
    case DATE:
      return DateFormatUtils.format(field.getValueAsDate(), "yyyy-MM-dd");
    case DATETIME:
      return DateFormatUtils.format(field.getValueAsDate(), "yyyy-MM-dd HH:mm:ss.SSS");
    case ZONED_DATETIME:
      return DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.format(
          field.getValueAsZonedDateTime().toInstant().toEpochMilli()
      );
    default:
      return String.valueOf(field.getValue());
  }
}
 
開發者ID:streamsets,項目名稱:datacollector,代碼行數:22,代碼來源:BaseTableJdbcSourceIT.java

示例10: feedBlocksPut

import org.apache.commons.lang3.time.DateFormatUtils; //導入方法依賴的package包/類
private void feedBlocksPut(Date currentDate, Date nextDate, CssLayout currentBlock) {
    MHorizontalLayout blockWrapper = new MHorizontalLayout().withSpacing(false).withFullWidth().withStyleName("feed-block-wrap");

    blockWrapper.setDefaultComponentAlignment(Alignment.TOP_LEFT);
    Calendar cal1 = Calendar.getInstance();
    cal1.setTime(currentDate);

    Calendar cal2 = Calendar.getInstance();
    cal2.setTime(nextDate);

    if (cal1.get(Calendar.YEAR) != cal2.get(Calendar.YEAR)) {
        int currentYear = cal2.get(Calendar.YEAR);
        Label yearLbl = ELabel.html("<div>" + String.valueOf(currentYear) + "</div>").withStyleName
                ("year-lbl").withWidthUndefined();
        listContainer.addComponent(yearLbl);
    } else {
        blockWrapper.setMargin(new MarginInfo(true, false, false, false));
    }
    Label dateLbl = new Label(DateFormatUtils.format(nextDate, "dd/MM"));
    dateLbl.setSizeUndefined();
    dateLbl.setStyleName("date-lbl");
    blockWrapper.with(dateLbl, currentBlock).expand(currentBlock);

    listContainer.addComponent(blockWrapper);
}
 
開發者ID:MyCollab,項目名稱:mycollab,代碼行數:26,代碼來源:ActivityStreamPanel.java

示例11: MomentFetcher

import org.apache.commons.lang3.time.DateFormatUtils; //導入方法依賴的package包/類
public MomentFetcher(Calendar startTime, MessageQueueInterface mqi) {
	this.cal = startTime;
	String timestamp = DateFormatUtils.format(this.cal,
			ConfigurationSingleton.instance
					.getConfigItem("replay.dateformat"));

	ArrayList<HTTPLogObject> thing = ReplayCache.instance
			.gimmieCache(timestamp);

	logger.info(thing.size() + " events for " + timestamp);
	
	for (HTTPLogObject s : thing) {
		mqi.deliver(s.getPayload());
		logger.debug(s.getPayload());
	}
	this.cal.add(Calendar.SECOND, 1);
}
 
開發者ID:broamski,項目名稱:cantilever,代碼行數:18,代碼來源:MomentFetcher.java

示例12: getPermalinkForUpdateArticle

import org.apache.commons.lang3.time.DateFormatUtils; //導入方法依賴的package包/類
/**
 * Gets article permalink for updating article with the specified old
 * article, article, create date.
 *
 * @param oldArticle
 *            the specified old article
 * @param article
 *            the specified article
 * @param createDate
 *            the specified create date
 * @return permalink
 * @throws ServiceException
 *             if invalid permalink occurs
 * @throws JSONException
 *             json exception
 */
private String getPermalinkForUpdateArticle(final JSONObject oldArticle, final JSONObject article,
		final Date createDate) throws ServiceException, JSONException {
	final String articleId = article.getString(Keys.OBJECT_ID);
	String ret = article.optString(ARTICLE_PERMALINK).trim();
	final String oldPermalink = oldArticle.getString(ARTICLE_PERMALINK);

	if (!oldPermalink.equals(ret)) {
		if (StringUtils.isBlank(ret)) {
			ret = "/articles/" + DateFormatUtils.format(createDate, "yyyy/MM/dd") + "/" + articleId + ".html";
		}

		if (!ret.startsWith("/")) {
			ret = "/" + ret;
		}

		if (PermalinkQueryService.invalidArticlePermalinkFormat(ret)) {
			throw new ServiceException(langPropsService.get("invalidPermalinkFormatLabel"));
		}

		if (!oldPermalink.equals(ret) && permalinkQueryService.exist(ret)) {
			throw new ServiceException(langPropsService.get("duplicatedPermalinkLabel"));
		}
	}

	return ret.replaceAll(" ", "-");
}
 
開發者ID:daima,項目名稱:solo-spring,代碼行數:43,代碼來源:ArticleMgmtService.java

示例13: daily

import org.apache.commons.lang3.time.DateFormatUtils; //導入方法依賴的package包/類
@Scheduled(cron = "0 5 8 * * *")
public void daily() {
    long start = System.currentTimeMillis();
    log.info("每日精選啟動...");

    try {
        String date = DateFormatUtils.format(new Date(), pattern);
        fanfouHandler.sendContent(dailyChatId, AppUtils.getFanFouDailyByDate(date));
    } catch (Exception e) {
        log.info(e.getMessage());
        appUtils.sendServerChan(e.getMessage(), ExceptionUtils.getStackTrace(e));
    }

    log.info("每日精選完成,耗時:{} ms", System.currentTimeMillis() - start);
}
 
開發者ID:junbaor,項目名稱:telegram-bot,代碼行數:16,代碼來源:FanfouTask.java

示例14: weekly

import org.apache.commons.lang3.time.DateFormatUtils; //導入方法依賴的package包/類
@Scheduled(cron = "0 0 12 * * mon")
public void weekly() {
    long start = System.currentTimeMillis();
    log.info("每周精選啟動...");

    try {
        String date = DateFormatUtils.format(new Date(), pattern);
        fanfouHandler.sendContent(weeklyChatId, AppUtils.getFanFouWeeklyByDate(date));
    } catch (Exception e) {
        log.info(e.getMessage());
        appUtils.sendServerChan(e.getMessage(), ExceptionUtils.getStackTrace(e));
    }

    log.info("每周精選完成,耗時:{} ms", System.currentTimeMillis() - start);
}
 
開發者ID:junbaor,項目名稱:telegram-bot,代碼行數:16,代碼來源:FanfouTask.java

示例15: getDeletedUSMarcIdList

import org.apache.commons.lang3.time.DateFormatUtils; //導入方法依賴的package包/類
@Override
public List<String> getDeletedUSMarcIdList(Date lastCheckedDate) {
	String lastDate = DateFormatUtils.format(lastCheckedDate, "yyyy-MM-dd");
	String sql = "select distinct marc_rec_no from " + dbUserPrefix + "marc where marc_type='U' and marc_rec_no in "
			+ " (select marc_rec_no from " + dbUserPrefix + "log_detl where (log_type='20017' or log_type='20014') and log_date>=? )";
	return (List<String>)getJdbcTemplate().query(sql, new Object[]{lastDate},new MarcRecNoExtractor());
}
 
開發者ID:ExLibrisChina,項目名稱:CatalogAutoExportKits_Huiwen,代碼行數:8,代碼來源:HuiwenMarcDaoImpl.java


注:本文中的org.apache.commons.lang3.time.DateFormatUtils.format方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。