本文整理匯總了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();
}
示例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);
}
示例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);
}
示例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);
}
示例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;
}
示例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;
}
示例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());
}
}
}
示例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());
}
}
示例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());
}
}
示例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);
}
示例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);
}
示例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(" ", "-");
}
示例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);
}
示例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);
}
示例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());
}