當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。