本文整理匯總了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);
}
}
示例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");
}
示例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");
}
示例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");
}
示例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);
}
}
示例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);
}
示例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;
}
示例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();
}
}
示例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;
}
示例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();
}
示例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;
}
示例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> ");
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, " ", " ");
htmlMessage = StringUtils.replace(htmlMessage, "\t", " ");
sb.append(htmlMessage);
}
sb.append("<br/>");
}
return sb.toString();
}
示例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);
}
示例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")));
}
}
示例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")));
}
}