本文整理汇总了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;
}