本文整理匯總了Java中org.apache.commons.lang.time.DateFormatUtils.format方法的典型用法代碼示例。如果您正苦於以下問題:Java DateFormatUtils.format方法的具體用法?Java DateFormatUtils.format怎麽用?Java DateFormatUtils.format使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.commons.lang.time.DateFormatUtils
的用法示例。
在下文中一共展示了DateFormatUtils.format方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: mapreduce
import org.apache.commons.lang.time.DateFormatUtils; //導入方法依賴的package包/類
@Test
public void mapreduce() {
MapReduceConfiguration mapReduceConfiguration = new MapReduceConfiguration();
long start = System.currentTimeMillis();
log.info("開始計算nginx月訪問日誌IP統計量");
try {
String inputPath = mapReduceConfiguration.url() + "/mapreduce/nginxlog/access/input";
String outputPath = mapReduceConfiguration.url() + "/mapreduce/nginxlog/access/output/month" + DateFormatUtils.format(new Date(), "yyyyMMddHHmmss");
MonthTrafficStatisticsMapReduce.main(new String[]{inputPath, outputPath});
mapReduceConfiguration.print(outputPath);
} catch (Exception e) {
log.error(e);
}
long end = System.currentTimeMillis();
log.info("運行mapreduce程序花費時間:" + (end - start) / 1000 + "s");
}
示例2: mapreduce
import org.apache.commons.lang.time.DateFormatUtils; //導入方法依賴的package包/類
@Test
public void mapreduce() {
MapReduceConfiguration mapReduceConfiguration = new MapReduceConfiguration();
long start = System.currentTimeMillis();
log.info("開始計算nginx訪問日誌IP統計量");
try {
String inputPath = mapReduceConfiguration.url() + "/mapreduce/nginxlog/access/input";
String outputPath = mapReduceConfiguration.url() + "/mapreduce/nginxlog/access/output/daily" + DateFormatUtils.format(new Date(), "yyyyMMddHHmmss");
ToolRunner.run(new DailyTrafficStatisticsMapRed(), new String[]{inputPath, outputPath});
mapReduceConfiguration.print(outputPath);
} catch (Exception e) {
log.error(e);
}
long end = System.currentTimeMillis();
log.info("運行mapreduce程序花費時間:" + (end - start) / 1000 + "s");
}
示例3: mapreduce
import org.apache.commons.lang.time.DateFormatUtils; //導入方法依賴的package包/類
@Test
public void mapreduce() {
MapReduceConfiguration mapReduceConfiguration = new MapReduceConfiguration();
long start = System.currentTimeMillis();
log.info("開始計算nginx年訪問日誌IP統計量");
try {
String inputPath = mapReduceConfiguration.url() + "/mapreduce/nginxlog/access/input";
String outputPath = mapReduceConfiguration.url() + "/mapreduce/nginxlog/access/output/year" + DateFormatUtils.format(new Date(), "yyyyMMddHHmmss");
YearTrafficStatisticsMapReduce.main(new String[]{inputPath, outputPath});
mapReduceConfiguration.print(outputPath);
} catch (Exception e) {
log.error(e);
}
long end = System.currentTimeMillis();
log.info("運行mapreduce程序花費時間:" + (end - start) / 1000 + "s");
}
示例4: mapreduce
import org.apache.commons.lang.time.DateFormatUtils; //導入方法依賴的package包/類
@Test
public void mapreduce() {
MapReduceConfiguration mapReduceConfiguration = new MapReduceConfiguration();
DistributedFileSystem distributedFileSystem = mapReduceConfiguration.distributedFileSystem();
try {
String inputPath = mapReduceConfiguration.url() + "/mapreduce/temperature/input";
Path inputpath = new Path(inputPath);
//文件不存在 則將輸入文件導入到hdfs中
if (!distributedFileSystem.exists(inputpath)) {
distributedFileSystem.mkdirs(inputpath);
distributedFileSystem.copyFromLocalFile(true, new Path(this.getClass().getClassLoader().getResource("mapred/temperature/input").getPath()), new Path(inputPath + "/input"));
}
String outputPath = mapReduceConfiguration.url() + "/mapreduce/temperature/mapred/output" + DateFormatUtils.format(new Date(), "yyyyMMddHHmmSS");
ToolRunner.run(new MaxTemperatureMapRed(), new String[]{inputPath, outputPath});
mapReduceConfiguration.print(outputPath);
} catch (Exception e) {
log.error(e);
e.printStackTrace();
} finally {
mapReduceConfiguration.close(distributedFileSystem);
}
}
示例5: mapreduce
import org.apache.commons.lang.time.DateFormatUtils; //導入方法依賴的package包/類
@Test
public void mapreduce() {
String inputPath = ParquetConfiguration.HDFS_URI + "//parquet/mapreduce/input";
String outputPath = ParquetConfiguration.HDFS_URI + "//parquet/mapreduce/output" + DateFormatUtils.format(new Date(), "yyyyMMddHHmmss");
try {
MapReduceParquetMapReducer.main(new String[]{inputPath, outputPath});
DistributedFileSystem distributedFileSystem = new ParquetConfiguration().distributedFileSystem();
FileStatus[] fileStatuses = distributedFileSystem.listStatus(new Path(outputPath));
for (FileStatus fileStatus : fileStatuses) {
System.out.println(fileStatus);
}
distributedFileSystem.close();
} catch (Exception e) {
e.printStackTrace();
}
}
示例6: exec
import org.apache.commons.lang.time.DateFormatUtils; //導入方法依賴的package包/類
@Override
public String exec(final Tuple tuple) throws IOException {
if (tuple == null || tuple.size() == 0) {
return null;
}
Object dateString = tuple.get(0);
if (dateString == null) {
return null;
}
try {
Date date = DateUtils.parseDate(dateString.toString(), new String[]{"yyyy-MM-dd HH:mm:ss"});
return DateFormatUtils.format(date, formatPattern);
} catch (ParseException e) {
e.printStackTrace();
}
return null;
}
示例7: getWeekArchive
import org.apache.commons.lang.time.DateFormatUtils; //導入方法依賴的package包/類
/**
* Gets the latest week archive (Sunday) with the specified time.
*
* @param time the specified time
* @return archive, returns {@code null} if not found
* @throws RepositoryException repository exception
*/
public JSONObject getWeekArchive(final long time) throws RepositoryException {
final long weekEndTime = Times.getWeekEndTime(time);
final String startDate = DateFormatUtils.format(time, "yyyyMMdd");
final String endDate = DateFormatUtils.format(weekEndTime, "yyyyMMdd");
final Query query = new Query().setCurrentPageNum(1).setPageCount(1).
addSort(Archive.ARCHIVE_DATE, SortDirection.DESCENDING).
setFilter(CompositeFilterOperator.and(
new PropertyFilter(Archive.ARCHIVE_DATE, FilterOperator.GREATER_THAN_OR_EQUAL, startDate),
new PropertyFilter(Archive.ARCHIVE_DATE, FilterOperator.LESS_THAN_OR_EQUAL, endDate)
));
final JSONObject result = get(query);
final JSONArray data = result.optJSONArray(Keys.RESULTS);
if (data.length() < 1) {
return null;
}
return data.optJSONObject(0);
}
示例8: processUploadedFile
import org.apache.commons.lang.time.DateFormatUtils; //導入方法依賴的package包/類
/**
* 解析上傳域
*
* @param item 文件對象
* @return {@link FileFormResult}
* @throws IOException IO異常
*/
private FileFormResult processUploadedFile(FileItem item) throws IOException {
String name = item.getName();
String fileSuffix = FilenameUtils.getExtension(name);
if (CollectionUtils.isNotEmpty(allowedSuffixList) && !allowedSuffixList.contains(fileSuffix)) {
throw new NotAllowedUploadException(String.format("上傳文件格式不正確,fileName=%s,allowedSuffixList=%s",
name, allowedSuffixList));
}
FileFormResult file = new FileFormResult();
file.setFieldName(item.getFieldName());
file.setFileName(name);
file.setContentType(item.getContentType());
file.setSizeInBytes(item.getSize());
//如果未設置上傳路徑,直接保存到項目根目錄
if (Strings.isNullOrEmpty(baseDir)) {
baseDir = request.getRealPath("/");
}
File relativePath = new File(SEPARATOR + DateFormatUtils.format(new Date(), "yyyyMMdd") + file.getFileName());
FileCopyUtils.copy(item.getInputStream(), new FileOutputStream(relativePath));
file.setSaveRelativePath(relativePath.getAbsolutePath());
return file;
}
示例9: process
import org.apache.commons.lang.time.DateFormatUtils; //導入方法依賴的package包/類
@Override
public void process(Exchange exchange) {
Date now = new Date();
String date = DateFormatUtils.format(now, "yyyyMMddhhmmss");
String nack = String.format(NACK_RESPONSE, date);
exchange.getOut().setBody(nack);
}
示例10: formatByDayPattern
import org.apache.commons.lang.time.DateFormatUtils; //導入方法依賴的package包/類
/**
* Format date by 'yyyy-MM-dd' pattern
*
* @param date
* @return
*/
public static String formatByDayPattern(Date date) {
if (date != null) {
return DateFormatUtils.format(date, DAY_PATTERN);
} else {
return null;
}
}
示例11: map
import org.apache.commons.lang.time.DateFormatUtils; //導入方法依賴的package包/類
@Override
protected void map(final LongWritable key, final Text value, final Context context) throws IOException, InterruptedException {
Map<String, Object> nginxLogMap = NginxAccessLogParser.parseLine(value.toString());
String remoteAddr = nginxLogMap.get("remoteAddr").toString();
Date accessTimeDate = (Date) nginxLogMap.get("accessTime");
String accessTime = DateFormatUtils.format(accessTimeDate, "yyyyMM");
context.write(new Text(accessTime), new Text(remoteAddr));
}
示例12: map
import org.apache.commons.lang.time.DateFormatUtils; //導入方法依賴的package包/類
@Override
protected void map(final LongWritable key, final Text value, final Context context) throws IOException, InterruptedException {
Map<String, Object> nginxLogMap = NginxAccessLogParser.parseLine(value.toString());
String remoteAddr = nginxLogMap.get("remoteAddr").toString();
Date accessTimeDate = (Date) nginxLogMap.get("accessTime");
String year = DateFormatUtils.format(accessTimeDate, "yyyy");
context.write(new Text(year), new Text(remoteAddr));
}
示例13: formatHeaderDate
import org.apache.commons.lang.time.DateFormatUtils; //導入方法依賴的package包/類
/**
* Formats the given date for use in the HTTP header
*
* @param date Date
* @return String
*/
public static String formatHeaderDate(Date date)
{
// HTTP header date/time format
// NOTE: According to RFC2616 dates should always be in English and in
// the GMT timezone see http://rfc.net/rfc2616.html#p20 for details
return DateFormatUtils.format(date, HEADER_IF_DATE_FORMAT, TimeZone.getTimeZone("GMT"), Locale.ENGLISH);
}
示例14: timeStampAsString
import org.apache.commons.lang.time.DateFormatUtils; //導入方法依賴的package包/類
public static String timeStampAsString(int numberOfPlaces) {
String answer = StringUtils.EMPTY;
Calendar cal = Calendar.getInstance();
String genDate = DateFormatUtils.format(cal, TestConstant.GENERATED_DATE);
answer = StringUtils.right(genDate, numberOfPlaces);
return answer;
}
示例15: bet1A0001
import org.apache.commons.lang.time.DateFormatUtils; //導入方法依賴的package包/類
/**
* Bets 1A0001.
*
* @param userId the specified user id
* @param amount the specified amount
* @param smallOrLarge the specified small or large
* @return result
*/
public synchronized JSONObject bet1A0001(final String userId, final int amount, final int smallOrLarge) {
final JSONObject ret = Results.falseResult();
if (activityQueryService.is1A0001Today(userId)) {
ret.put(Keys.MSG, langPropsService.get("activityParticipatedLabel"));
return ret;
}
final String date = DateFormatUtils.format(new Date(), "yyyyMMdd");
final boolean succ = null != pointtransferMgmtService.transfer(userId, Pointtransfer.ID_C_SYS,
Pointtransfer.TRANSFER_TYPE_C_ACTIVITY_1A0001, amount, date + "-" + smallOrLarge);
ret.put(Keys.STATUS_CODE, succ);
final String msg = succ
? langPropsService.get("activityBetSuccLabel") : langPropsService.get("activityBetFailLabel");
ret.put(Keys.MSG, msg);
try {
final JSONObject user = userQueryService.getUser(userId);
final String userName = user.optString(User.USER_NAME);
// Timeline
final JSONObject timeline = new JSONObject();
timeline.put(Common.TYPE, Common.ACTIVITY);
String content = langPropsService.get("timelineActivity1A0001Label");
content = content.replace("{user}", "<a target='_blank' rel='nofollow' href='" + Latkes.getServePath()
+ "/member/" + userName + "'>" + userName + "</a>");
timeline.put(Common.CONTENT, content);
timelineMgmtService.addTimeline(timeline);
} catch (final ServiceException e) {
LOGGER.log(Level.ERROR, "Timeline error", e);
}
return ret;
}