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


Java DateFormatUtils類代碼示例

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


DateFormatUtils類屬於org.apache.commons.lang3.time包,在下文中一共展示了DateFormatUtils類的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: addArchives

import org.apache.commons.lang3.time.DateFormatUtils; //導入依賴的package包/類
/**
 * Adds archives (archive-articles) into the specified sitemap.
 * 
 * @param sitemap
 *            the specified sitemap
 * @throws Exception
 *             exception
 */
private void addArchives(final Sitemap sitemap) throws Exception {
	final JSONObject result = archiveDateDao.get(new Query());
	final JSONArray archiveDates = result.getJSONArray(Keys.RESULTS);

	for (int i = 0; i < archiveDates.length(); i++) {
		final JSONObject archiveDate = archiveDates.getJSONObject(i);
		final long time = archiveDate.getLong(ArchiveDate.ARCHIVE_TIME);
		final String dateString = DateFormatUtils.format(time, "yyyy/MM");

		final URL url = new URL();

		url.setLoc(Latkes.getServePath() + "/archives/" + dateString);

		sitemap.addURL(url);
	}
}
 
開發者ID:daima,項目名稱:solo-spring,代碼行數:25,代碼來源:SitemapProcessor.java

示例3: getPermalinkForAddArticle

import org.apache.commons.lang3.time.DateFormatUtils; //導入依賴的package包/類
/**
 * Gets article permalink for adding article with the specified article.
 *
 * @param article
 *            the specified article
 * @return permalink
 * @throws ServiceException
 *             if invalid permalink occurs
 */
private String getPermalinkForAddArticle(final JSONObject article) throws ServiceException {
	final Date date = (Date) article.opt(Article.ARTICLE_CREATE_DATE);

	String ret = article.optString(Article.ARTICLE_PERMALINK);

	if (StringUtils.isBlank(ret)) {
		ret = "/articles/" + DateFormatUtils.format(date, "yyyy/MM/dd") + "/" + article.optString(Keys.OBJECT_ID)
				+ ".html";
	}

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

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

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

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

示例4: parseAndUpdate

import org.apache.commons.lang3.time.DateFormatUtils; //導入依賴的package包/類
private void parseAndUpdate(Date queryDate, String directory, PostgreStorage storage,
    String market)
    throws IOException, ParseException {
  List<StockShareholding> stockShareholdings = parse(queryDate, directory);
  if (!stockShareholdings.isEmpty()) {
    if (stockShareholdings.get(0).getDate().equals(queryDate)) {
      storage.saveShareholdings(stockShareholdings, market);
      logger.info("Market {} date {} data has been parsed and updated", market,
          DateFormatUtils.format(queryDate, "yyyy-MM-dd"));
    } else {
      logger.warn("Market {} date {} data in an inconsistent state, operation skipped", market,
          DateFormatUtils.format(queryDate, "yyyy-MM-dd"));
    }
  } else {
    logger.info("Market {} date {} data not existed, operation skipped", market,
        DateFormatUtils.format(queryDate, "yyyy-MM-dd"));
  }
}
 
開發者ID:longkerdandy,項目名稱:qfii-tracker,代碼行數:19,代碼來源:ConnectParser.java

示例5: asString

import org.apache.commons.lang3.time.DateFormatUtils; //導入依賴的package包/類
static String asString(final DateColumn column) {
	if (null == column.asDate()) {
		return null;
	}

	switch (column.getSubType()) {
	case DATE:
		return DateFormatUtils.format(column.asDate(), DateCast.dateFormat,
				DateCast.timeZoner);
	case TIME:
		return DateFormatUtils.format(column.asDate(), DateCast.timeFormat,
				DateCast.timeZoner);
	case DATETIME:
		return DateFormatUtils.format(column.asDate(),
				DateCast.datetimeFormat, DateCast.timeZoner);
	default:
		throw DataXException
				.asDataXException(CommonErrorCode.CONVERT_NOT_SUPPORT,
						"時間類型出現不支持類型,目前僅支持DATE/TIME/DATETIME。該類型屬於編程錯誤,請反饋給DataX開發團隊 .");
	}
}
 
開發者ID:yaogdu,項目名稱:datax,代碼行數:22,代碼來源:ColumnCast.java

示例6: storeConfig

import org.apache.commons.lang3.time.DateFormatUtils; //導入依賴的package包/類
/**
 * 緩存配置
 */
public void storeConfig(Map<String, String> properties) {
    try {
        // 如果緩存文件不存在,則創建
        FileUtils.createFileIfAbsent(cacheFile.getPath());
        OutputStream out = null;
        try {
            out = new FileOutputStream(cacheFile);
            mapToProps(properties).store(out, "updated at " + DateFormatUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss"));
        } finally {
            if (out != null) {
                out.close();
            }
        }
    } catch (IOException e) {
        ExceptionUtils.rethrow(e);
    }
}
 
開發者ID:zhongxunking,項目名稱:configcenter,代碼行數:21,代碼來源:CacheFileHandler.java

示例7: getMonthFirstDay

import org.apache.commons.lang3.time.DateFormatUtils; //導入依賴的package包/類
/** 
 * @Title:getMonthFirstDay 
 * @Description: 得到當前月的第一天. 
 * @return 
 * @return String 
 */  
public static String getMonthFirstDay() {  
    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));  
    // f.set(Calendar.DAY_OF_MONTH, cal.getActualMinimum(Calendar.DATE));  
    // return DateFormatUtils.format(f, DATE_FORMAT);  
  
    // 方法二.  
    cal.set(Calendar.DATE, 1);  
    return DateFormatUtils.format(cal, DATE_FORMAT);  
  
}
 
開發者ID:phoenix2014,項目名稱:rexxar,代碼行數:22,代碼來源:RexxarDateUtils.java

示例8: 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

示例9: getPreviousMonthFirst

import org.apache.commons.lang3.time.DateFormatUtils; //導入依賴的package包/類
/** 
 * @Title:getPreviousMonthFirst 
 * @Description: 得到上個月的第一天 
 * @return 
 * @return String 
 */  
public static String getPreviousMonthFirst() {  
    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);  
    // return DateFormatUtils.format(f, DATE_FORMAT);  
  
    // 方法二  
    // f.set(Calendar.YEAR, cal.get(Calendar.YEAR));  
    // f.set(Calendar.MONTH, cal.get(Calendar.MONTH) - 1);  
    // 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);  
    return DateFormatUtils.format(cal, DATE_FORMAT);  
}
 
開發者ID:phoenix2014,項目名稱:rexxar,代碼行數:28,代碼來源:RexxarDateUtils.java

示例10: getPreviousMonthEnd

import org.apache.commons.lang3.time.DateFormatUtils; //導入依賴的package包/類
/** 
 * @Title:getPreviousMonthEnd 
 * @Description: 得到上個月最後一天 
 * @return 
 * @return String 
 */  
public static String getPreviousMonthEnd() {  
    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));  
    // 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) - 1);  
    // 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, 0);//  
    cal.add(Calendar.DATE, -1);// 減去一天,變為當月最後一天  
    return DateFormatUtils.format(cal, DATE_FORMAT);  
}
 
開發者ID:phoenix2014,項目名稱:rexxar,代碼行數:29,代碼來源:RexxarDateUtils.java

示例11: 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

示例12: getDaysListBetweenDates

import org.apache.commons.lang3.time.DateFormatUtils; //導入依賴的package包/類
/** 
 * @Title:getDaysListBetweenDates 
 * @Description: 獲得兩個日期之間的連續日期. 
 * @param begin 
 *            開始日期 . 
 * @param end 
 *            結束日期 . 
 * @return 
 * @return List<String> 
 */  
public static List<String> getDaysListBetweenDates(String begin, String end) {  
    List<String> dateList = new ArrayList<String>();  
    Date d1;  
    Date d2;  
    try {  
        d1 = DateUtils.parseDate(begin, DATE_FORMAT);  
        d2 = DateUtils.parseDate(end, DATE_FORMAT);  
        if (d1.compareTo(d2) > 0) {  
            return dateList;  
        }  
        do {  
            dateList.add(DateFormatUtils.format(d1, DATE_FORMAT));  
            d1 = DateUtils.addDays(d1, 1);  
        } while (d1.compareTo(d2) <= 0);  
    } catch (ParseException e) {  
        e.printStackTrace();  
    }  
    return dateList;  
}
 
開發者ID:phoenix2014,項目名稱:rexxar,代碼行數:30,代碼來源:RexxarDateUtils.java

示例13: getMonthsListBetweenDates

import org.apache.commons.lang3.time.DateFormatUtils; //導入依賴的package包/類
/** 
 * @Title:getMonthsListBetweenDates 
 * @Description: 獲得連續的月份 
 * @param begin 
 * @param end 
 * @return 
 * @return List<String> 
 */  
public static List<String> getMonthsListBetweenDates(String begin, String end) {  
    List<String> dateList = new ArrayList<String>();  
    Date d1;  
    Date d2;  
    try {  
        d1 = DateUtils.parseDate(begin, DATE_FORMAT);  
        d2 = DateUtils.parseDate(end, DATE_FORMAT);  
        if (d1.compareTo(d2) > 0) {  
            return dateList;  
        }  
        do {  
            dateList.add(DateFormatUtils.format(d1, MONTH_FORMAT));  
            d1 = DateUtils.addMonths(d1, 1);  
        } while (d1.compareTo(d2) <= 0);  
    } catch (ParseException e) {  
        e.printStackTrace();  
    }  
    return dateList;  
}
 
開發者ID:phoenix2014,項目名稱:rexxar,代碼行數:28,代碼來源:RexxarDateUtils.java

示例14: toString

import org.apache.commons.lang3.time.DateFormatUtils; //導入依賴的package包/類
@Override
public String toString() {
	StringBuilder builder = new StringBuilder();
	builder.append("[");
	if( this.start == null )
		builder.append("start=null");
	else
		builder.append("start="+DateFormatUtils.ISO_DATETIME_FORMAT.format(this.start));
	builder.append(", ");
	if( this.end == null )
		builder.append("end=null");
	else
		builder.append("end="+DateFormatUtils.ISO_DATETIME_FORMAT.format(this.end));
	builder.append("]");
	return builder.toString();
}
 
開發者ID:cybozu,項目名稱:garoon-google,代碼行數:17,代碼來源:Span.java

示例15: onSecurityDefinition

import org.apache.commons.lang3.time.DateFormatUtils; //導入依賴的package包/類
@Override
public int onSecurityDefinition(final String channelId, final MdpMessage mdpMessage) {
    SbeString secGroup = SbeString.allocate(10);
    mdpMessage.getString(1151, secGroup);
    int securityID = mdpMessage.getInt32(48);
    short marketSegmentID = mdpMessage.getUInt8(1300);
    double strikePrice = 0;
    if(mdpMessage.hasField(202)) {
        strikePrice = mdpMessage.getInt64(202) * Math.pow(10, -7);
    }
    String securityGroup = secGroup.getString();
    MdpGroup mdpGroup = SbeGroup.instance();
    mdpMessage.getGroup(864, mdpGroup);
    MdpGroupEntry mdpGroupEntry = SbeGroupEntry.instance();

    logger.info("Received SecurityDefinition(d). securityID '{}', ChannelId: {}, Schema Id: {}, securityGroup '{}', marketSegmentID '{}', strikePrice '{}'", securityID, channelId, mdpMessage.getSchemaId(), securityGroup, marketSegmentID, strikePrice);
    while (mdpGroup.hashNext()){
        mdpGroup.next();
        mdpGroup.getEntry(mdpGroupEntry);
        long eventTime = mdpGroupEntry.getUInt64(1145);
        short eventType = mdpGroupEntry.getUInt8(865);
        logger.info("eventTime - '{}'({}), eventType - '{}'", DateFormatUtils.format(eventTime/1000000, "yyyyMMdd HHmm", TimeZone.getTimeZone("UTC")), eventTime, eventType);
    }
    return MdEventFlags.MESSAGE;
}
 
開發者ID:epam,項目名稱:java-cme-mdp3-handler,代碼行數:26,代碼來源:MBOWithMBPMain.java


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