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


Java DateFormatUtils类代码示例

本文整理汇总了Java中org.apache.commons.lang.time.DateFormatUtils的典型用法代码示例。如果您正苦于以下问题:Java DateFormatUtils类的具体用法?Java DateFormatUtils怎么用?Java DateFormatUtils使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


DateFormatUtils类属于org.apache.commons.lang.time包,在下文中一共展示了DateFormatUtils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getNext

import org.apache.commons.lang.time.DateFormatUtils; //导入依赖的package包/类
@Override
public Tuple getNext() throws IOException {
    try {
        boolean flag = recordReader.nextKeyValue();
        if (!flag) {
            return null;
        }
        Text value = (Text) recordReader.getCurrentValue();
        Map<String, Object> stringObjectMap = NginxAccessLogParser.parseLine(value.toString());
        List propertiyList = new ArrayList<String>();
        propertiyList.add(0, stringObjectMap.get("remoteAddr"));
        propertiyList.add(1, DateFormatUtils.format((Date) stringObjectMap.get("accessTime"), "yyyy-MM-dd HH:mm:ss"));
        propertiyList.add(2, stringObjectMap.get("method"));

        propertiyList.add(3, stringObjectMap.get("url"));
        propertiyList.add(4, stringObjectMap.get("protocol"));
        propertiyList.add(5, stringObjectMap.get("agent"));

        propertiyList.add(6, stringObjectMap.get("refer"));
        propertiyList.add(7, stringObjectMap.get("status"));
        propertiyList.add(8, stringObjectMap.get("length"));
        return TupleFactory.getInstance().newTuple(propertiyList);
    } catch (InterruptedException e) {
        throw new ExecException("Read data error", PigException.REMOTE_ENVIRONMENT, e);
    }
}
 
开发者ID:mumuhadoop,项目名称:mumu-pig,代码行数:27,代码来源:NginxLogLoader.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/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

示例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/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

示例4: 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

示例5: 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

示例6: testNodeStatus

import org.apache.commons.lang.time.DateFormatUtils; //导入依赖的package包/类
@Test
public void testNodeStatus() throws Exception {
  NodeId nodeId = NodeId.newInstance("host0", 0);
  NodeCLI cli = new NodeCLI();
  when(client.getNodeReports()).thenReturn(
                  getNodeReports(3, NodeState.RUNNING, false));
  cli.setClient(client);
  cli.setSysOutPrintStream(sysOut);
  cli.setSysErrPrintStream(sysErr);
  int result = cli.run(new String[] { "-status", nodeId.toString() });
  assertEquals(0, result);
  verify(client).getNodeReports();
  ByteArrayOutputStream baos = new ByteArrayOutputStream();
  PrintWriter pw = new PrintWriter(baos);
  pw.println("Node Report : ");
  pw.println("\tNode-Id : host0:0");
  pw.println("\tRack : rack1");
  pw.println("\tNode-State : RUNNING");
  pw.println("\tNode-Http-Address : host1:8888");
  pw.println("\tLast-Health-Update : "
    + DateFormatUtils.format(new Date(0), "E dd/MMM/yy hh:mm:ss:SSzz"));
  pw.println("\tHealth-Report : ");
  pw.println("\tContainers : 0");
  pw.println("\tMemory-Used : 0MB");
  pw.println("\tMemory-Capacity : 0MB");
  pw.println("\tCPU-Used : 0 vcores");
  pw.println("\tCPU-Capacity : 0 vcores");
  pw.println("\tNode-Labels : a,b,c,x,y,z");
  pw.close();
  String nodeStatusStr = baos.toString("UTF-8");
  verify(sysOut, times(1)).println(isA(String.class));
  verify(sysOut).println(nodeStatusStr);
}
 
开发者ID:naver,项目名称:hadoop,代码行数:34,代码来源:TestYarnCLI.java

示例7: 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

示例8: 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

示例9: timeAsHexDigitsString

import org.apache.commons.lang.time.DateFormatUtils; //导入依赖的package包/类
public static String timeAsHexDigitsString(int numberOfPlaces) {
    String answer = StringUtils.EMPTY;
    Calendar cal = Calendar.getInstance();
    String year = DateFormatUtils.format(cal, "yy");
    String month = DateFormatUtils.format(cal, "MM");
    String day = DateFormatUtils.format(cal, "dd");
    String hour = DateFormatUtils.format(cal, "kk");
    String minute = DateFormatUtils.format(cal, "mm");
    String second = DateFormatUtils.format(cal, "ss");

    answer += Long.toHexString(Long.parseLong(year));
    answer += Long.toHexString(Long.parseLong(month));
    answer += Long.toHexString(Long.parseLong(day));
    answer += Long.toHexString(Long.parseLong(hour));
    answer += Long.toHexString(Long.parseLong(minute));
    answer += Long.toHexString(Long.parseLong(second));

    answer = StringUtils.right(answer, numberOfPlaces);
    return answer;
}
 
开发者ID:AgileTestingFramework,项目名称:atf-toolbox-java,代码行数:21,代码来源:DateUtil.java

示例10: copyDemographicTransferDataToScorePlaceholder

import org.apache.commons.lang.time.DateFormatUtils; //导入依赖的package包/类
private static void copyDemographicTransferDataToScorePlaceholder(LoggedInInfo loggedInInfo, Facility facility,DemographicTransfer demographicTransfer, LinkedDemographicHolder integratorLinkedDemographicHolder) throws MalformedURLException {
	// copy the data to holder entry
	if (demographicTransfer.getBirthDate() != null) integratorLinkedDemographicHolder.birthDate = DateFormatUtils.ISO_DATE_FORMAT.format(demographicTransfer.getBirthDate());
	integratorLinkedDemographicHolder.firstName = StringUtils.trimToEmpty(demographicTransfer.getFirstName());
	integratorLinkedDemographicHolder.gender = "";
	if (demographicTransfer.getGender()!=null) integratorLinkedDemographicHolder.gender=demographicTransfer.getGender().name();
	integratorLinkedDemographicHolder.hin = StringUtils.trimToEmpty(demographicTransfer.getHin());
	integratorLinkedDemographicHolder.hinType = StringUtils.trimToEmpty(demographicTransfer.getHinType());
	integratorLinkedDemographicHolder.lastName = StringUtils.trimToEmpty(demographicTransfer.getLastName());

	CachedFacility tempFacility = CaisiIntegratorManager.getRemoteFacility(loggedInInfo, facility,demographicTransfer.getIntegratorFacilityId());
	integratorLinkedDemographicHolder.linkDestination = ClientLink.Type.OSCAR_CAISI.name() + '.' + tempFacility.getIntegratorFacilityId();
	integratorLinkedDemographicHolder.remoteLinkId = demographicTransfer.getCaisiDemographicId();
	
	if (demographicTransfer.getPhoto()!=null) integratorLinkedDemographicHolder.imageUrl="/imageRenderingServlet?source="+ImageRenderingServlet.Source.integrator_client.name()+"&integratorFacilityId=" + demographicTransfer.getIntegratorFacilityId()+"&caisiDemographicId=" + demographicTransfer.getCaisiDemographicId();
}
 
开发者ID:williamgrosset,项目名称:OSCAR-ConCert,代码行数:17,代码来源:ManageLinkedClients.java

示例11: 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

示例12: writeLog

import org.apache.commons.lang.time.DateFormatUtils; //导入依赖的package包/类
private String writeLog() {
    StringBuilder sb = new StringBuilder();
    List<LogItem> items = App.getInstance().getAppLog().getItems();
    for (LogItem item : items) {
        sb.append("<b>");
        sb.append(DateFormatUtils.format(item.getTimestamp(), DATE_FORMAT));
        sb.append(" ");
        sb.append(item.getLevel().name());
        sb.append("</b>&nbsp;");
        sb.append(StringEscapeUtils.escapeHtml(item.getMessage()));
        if (item.getStacktrace() != null) {
            sb.append(" ");

            String htmlMessage = StringEscapeUtils.escapeHtml(item.getStacktrace());
            htmlMessage = StringUtils.replace(htmlMessage, "\n", "<br/>");
            htmlMessage = StringUtils.replace(htmlMessage, " ", "&nbsp;");
            htmlMessage = StringUtils.replace(htmlMessage, "\t", "&nbsp;&nbsp;&nbsp;&nbsp;");

            sb.append(htmlMessage);
        }
        sb.append("<br/>");
    }
    return sb.toString();
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:25,代码来源:LogWindow.java

示例13: 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

示例14: testFullErrorResponse

import org.apache.commons.lang.time.DateFormatUtils; //导入依赖的package包/类
@Test
public void testFullErrorResponse() throws XMLStreamException, AciErrorException, ProcessorException {
    try {
        // Execute the processor...
        processor.process(XmlTestUtils.getResourceAsXMLStreamReader("/com/autonomy/aci/client/services/processor/errorProcessorTestFullErrorResponse.xml"));
        fail("Should have thrown an AciErrorException");
    } catch (final AciErrorException exception) {
        // Check it...
        assertThat("errorId property not as expected.", exception.getErrorId(), is(equalTo("AutonomyIDOLServerWOBBLE1")));
        assertThat("rawErrorId property not as expected.", exception.getRawErrorId(), is(nullValue()));
        assertThat("errorString property not as expected.", exception.getErrorString(), is(equalTo("ERROR")));
        assertThat("errorDescription property not as expected.", exception.getErrorDescription(), is(equalTo("The requested action was not recognised")));
        assertThat("errorCode property not as expected.", exception.getErrorCode(), is(equalTo("ERRORNOTIMPLEMENTED")));
        assertThat("errorTime property not as expected.", DateFormatUtils.format(exception.getErrorTime(), "dd MMM yy HH:mm:ss"), is(equalTo("06 Feb 06 17:03:54")));
    }
}
 
开发者ID:hpe-idol,项目名称:java-aci-api-ng,代码行数:17,代码来源:ErrorProcessorTest.java

示例15: testFullErrorResponseRawErrorId

import org.apache.commons.lang.time.DateFormatUtils; //导入依赖的package包/类
@Test
public void testFullErrorResponseRawErrorId() throws XMLStreamException, AciErrorException, ProcessorException {
    try {
        // Execute the processor...
        processor.process(XmlTestUtils.getResourceAsXMLStreamReader("/com/autonomy/aci/client/services/processor/errorProcessorTestFullErrorResponseRawErrorId.xml"));
        fail("Should have thrown an AciErrorException");
    } catch (final AciErrorException exception) {
        // Check it...
        assertThat("errorId property not as expected.", exception.getErrorId(), is(equalTo("DAHGETQUERYTAGVALUES525")));
        assertThat("rawErrorId property not as expected.", exception.getRawErrorId(), is(equalTo("0x20D")));
        assertThat("errorString property not as expected.", exception.getErrorString(), is(equalTo("No valid parametric fields")));
        assertThat("errorDescription property not as expected.", exception.getErrorDescription(), is(equalTo("The fieldname parameter contained no valid parametric fields")));
        assertThat("errorCode property not as expected.", exception.getErrorCode(), is(equalTo("ERRORPARAMINVALID")));
        assertThat("errorTime property not as expected.", DateFormatUtils.format(exception.getErrorTime(), "dd MMM yy HH:mm:ss"), is(equalTo("09 Jul 08 15:48:22")));
    }
}
 
开发者ID:hpe-idol,项目名称:java-aci-api-ng,代码行数:17,代码来源:ErrorProcessorTest.java


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