当前位置: 首页>>代码示例>>Java>>正文


Java DateFormatUtils.format方法代码示例

本文整理汇总了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");
}
 
开发者ID:mumuhadoop,项目名称:mumu-mapreduce,代码行数:17,代码来源:MonthTrafficStatisticsMapReduceTest.java

示例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");
}
 
开发者ID:mumuhadoop,项目名称:mumu-mapreduce,代码行数:17,代码来源:DailyTrafficStatisticsMapRedTest.java

示例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");
}
 
开发者ID:mumuhadoop,项目名称:mumu-mapreduce,代码行数:17,代码来源:YearTrafficStatisticsMapReduceTest.java

示例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);
    }
}
 
开发者ID:mumuhadoop,项目名称:mumu-mapreduce,代码行数:24,代码来源:MaxTemperatureMapRedTest.java

示例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();
    }
}
 
开发者ID:mumuhadoop,项目名称:mumu-parquet,代码行数:17,代码来源:MapReduceParquetMapReducerTest.java

示例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;
}
 
开发者ID:mumuhadoop,项目名称:mumu-pig,代码行数:18,代码来源:DateFormatEval.java

示例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);
}
 
开发者ID:FangStarNet,项目名称:symphonyx,代码行数:28,代码来源:ArchiveRepository.java

示例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;
}
 
开发者ID:glameyzhou,项目名称:scaffold,代码行数:30,代码来源:Uploader.java

示例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);
}
 
开发者ID:KingsCollegeHospital,项目名称:rassyeyanie,代码行数:10,代码来源:SimpleExceptionProcessor.java

示例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;
    }
}
 
开发者ID:baidu,项目名称:uid-generator,代码行数:14,代码来源:DateUtils.java

示例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));
}
 
开发者ID:mumuhadoop,项目名称:mumu-mapreduce,代码行数:9,代码来源:MonthTrafficStatisticsMapReduce.java

示例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));
}
 
开发者ID:mumuhadoop,项目名称:mumu-mapreduce,代码行数:9,代码来源:YearTrafficStatisticsMapReduce.java

示例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);
}
 
开发者ID:Alfresco,项目名称:alfresco-remote-api,代码行数:14,代码来源:WebDAV.java

示例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;
}
 
开发者ID:AgileTestingFramework,项目名称:atf-toolbox-java,代码行数:8,代码来源:DateUtil.java

示例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;
}
 
开发者ID:FangStarNet,项目名称:symphonyx,代码行数:48,代码来源:ActivityMgmtService.java


注:本文中的org.apache.commons.lang.time.DateFormatUtils.format方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。