本文整理匯總了Java中org.apache.commons.lang.time.DateUtils類的典型用法代碼示例。如果您正苦於以下問題:Java DateUtils類的具體用法?Java DateUtils怎麽用?Java DateUtils使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
DateUtils類屬於org.apache.commons.lang.time包,在下文中一共展示了DateUtils類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getDateOfRelease
import org.apache.commons.lang.time.DateUtils; //導入依賴的package包/類
public Date getDateOfRelease() {
if (StringUtils.isEmpty(releaseDate)) {
return null;
}
try {
return DateUtils.parseDate(this.releaseDate, new String[]{"yyyy-MM-dd"});
} catch (ParseException e) {
return null;
}
}
示例2: fetchReleaseRecord
import org.apache.commons.lang.time.DateUtils; //導入依賴的package包/類
private CmsRelease fetchReleaseRecord(String nsPath, Date ts, int genTime) throws InterruptedException {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(CmsConstants.SEARCH_TS_PATTERN);
Thread.sleep(3000);
SearchQuery latestRelease = new NativeSearchQueryBuilder()
.withIndices("cms-*")
.withTypes("release").withFilter(
FilterBuilders.andFilter(
FilterBuilders.queryFilter(QueryBuilders.termQuery("nsPath.keyword", nsPath)),
FilterBuilders.queryFilter(QueryBuilders.rangeQuery("created").
from(simpleDateFormat.format(DateUtils.addMinutes(ts, -(genTime + 10)))).
to(simpleDateFormat.format(ts))))).
withSort(SortBuilders.fieldSort("created").order(SortOrder.DESC)).build();
List<CmsReleaseSearch> ciList = indexer.getTemplate().queryForList(latestRelease, CmsReleaseSearch.class);
if (!ciList.isEmpty()) {
return ciList.get(0);
}
throw new RuntimeException("Cant find bom release for deployment plan generation event");
}
示例3: doExpand
import org.apache.commons.lang.time.DateUtils; //導入依賴的package包/類
@Override
protected String doExpand(String macro) {
count++;
String[] args = macro.split(",");
if (args.length != 1 && args.length != 2)
throw new RuntimeException("Invalid macro: " + macro);
String field = args[0].trim();
String param1 = field.replace(".", "_") + "_" + count + "_1";
String param2 = field.replace(".", "_") + "_" + count + "_2";
TimeZone timeZone = getTimeZoneFromArgs(args, 1);
if (timeZone == null) {
timeZone = TimeZone.getDefault();
}
Calendar cal = Calendar.getInstance(timeZone);
cal.setTime(AppBeans.get(TimeSource.class).currentTimestamp());
params.put(param1, DateUtils.truncate(cal, Calendar.DAY_OF_MONTH).getTime());
cal.add(Calendar.DAY_OF_MONTH, 1);
params.put(param2, DateUtils.truncate(cal, Calendar.DAY_OF_MONTH).getTime());
return String.format("(%s >= :%s and %s < :%s)", field, param1, field, param2);
}
示例4: modifyReleaseForm
import org.apache.commons.lang.time.DateUtils; //導入依賴的package包/類
/**
* 更改發布單
*
* @param appId
* @param formId 發布單ID
* @param name 發布單名稱
* @param remark 發布單備注
* @param planPubTime 計劃發布時間
* @return
*/
@RequestMapping(value = "/apps/{appId}/releaseform/{formId}", method = RequestMethod.PUT)
@ResponseBody
public Object modifyReleaseForm(@PathVariable("appId") int appId,
@PathVariable("formId") long formId,
@RequestParam("name") String name,
@RequestParam("remark") String remark, @RequestParam("planPubTime") String planPubTime) throws ParseException {
Date planPubDate = null;
if (StringUtils.isNotEmpty(planPubTime)) {
planPubDate = DateUtils.parseDate(planPubTime, new String[]{"yyyy-MM-dd HH:mm:ss"});
}
releaseFormService.modifyForm(appId, formId, name, remark, planPubDate);
return releaseFormService.getReleaseForm(formId);
}
示例5: filterByCreateDate
import org.apache.commons.lang.time.DateUtils; //導入依賴的package包/類
/**
* 使用創建日期來過濾發布單
*
* @param releaseForms
* @param createDate
* @return
*/
private List<ReleaseForm> filterByCreateDate(List<ReleaseForm> releaseForms, Date createDate) {
// 未限定
if (createDate == null) {
return releaseForms;
}
List<ReleaseForm> filteredReleaseFormList = new ArrayList<>();
for (ReleaseForm form : releaseForms) {
if (DateUtils.isSameDay(form.getCreateTime(), createDate)) {
filteredReleaseFormList.add(form);
}
}
return filteredReleaseFormList;
}
示例6: filterByReleaseDate
import org.apache.commons.lang.time.DateUtils; //導入依賴的package包/類
/**
* 使用發布日期來過濾發布單
*
* @param releaseForms
* @param releaseDate
* @return
*/
private List<ReleaseForm> filterByReleaseDate(List<ReleaseForm> releaseForms, Date releaseDate) {
// 未限定
if (releaseDate == null) {
return releaseForms;
}
List<ReleaseForm> filteredReleaseFormList = new ArrayList<>();
for (ReleaseForm form : releaseForms) {
if (DateUtils.isSameDay(form.getCreateTime(), releaseDate)) {
filteredReleaseFormList.add(form);
}
}
return filteredReleaseFormList;
}
示例7: updateAttemptMetrics
import org.apache.commons.lang.time.DateUtils; //導入依賴的package包/類
private static void updateAttemptMetrics(RMContainerImpl container) {
// If this is a preempted container, update preemption metrics
Resource resource = container.getContainer().getResource();
RMAppAttempt rmAttempt = container.rmContext.getRMApps()
.get(container.getApplicationAttemptId().getApplicationId())
.getCurrentAppAttempt();
if (ContainerExitStatus.PREEMPTED == container.finishedStatus
.getExitStatus()) {
rmAttempt.getRMAppAttemptMetrics().updatePreemptionInfo(resource,
container);
}
if (rmAttempt != null) {
long usedMillis = container.finishTime - container.creationTime;
long memorySeconds = resource.getMemory()
* usedMillis / DateUtils.MILLIS_PER_SECOND;
long vcoreSeconds = resource.getVirtualCores()
* usedMillis / DateUtils.MILLIS_PER_SECOND;
long gcoreSeconds = resource.getGpuCores()
* usedMillis / DateUtils.MILLIS_PER_SECOND;
rmAttempt.getRMAppAttemptMetrics()
.updateAggregateAppResourceUsage(memorySeconds,vcoreSeconds, gcoreSeconds);
}
}
示例8: getRunningAggregateAppResourceUsage
import org.apache.commons.lang.time.DateUtils; //導入依賴的package包/類
synchronized AggregateAppResourceUsage getRunningAggregateAppResourceUsage() {
long currentTimeMillis = System.currentTimeMillis();
// Don't walk the whole container list if the resources were computed
// recently.
if ((currentTimeMillis - lastMemoryAggregateAllocationUpdateTime)
> MEM_AGGREGATE_ALLOCATION_CACHE_MSECS) {
long memorySeconds = 0;
long vcoreSeconds = 0;
long gcoreSeconds = 0;
for (RMContainer rmContainer : this.liveContainers.values()) {
long usedMillis = currentTimeMillis - rmContainer.getCreationTime();
Resource resource = rmContainer.getContainer().getResource();
memorySeconds += resource.getMemory() * usedMillis /
DateUtils.MILLIS_PER_SECOND;
vcoreSeconds += resource.getVirtualCores() * usedMillis
/ DateUtils.MILLIS_PER_SECOND;
gcoreSeconds += resource.getGpuCores() * usedMillis / DateUtils.MILLIS_PER_SECOND;
}
lastMemoryAggregateAllocationUpdateTime = currentTimeMillis;
lastMemorySeconds = memorySeconds;
lastVcoreSeconds = vcoreSeconds;
lastGcoreSeconds = gcoreSeconds;
}
return new AggregateAppResourceUsage(lastMemorySeconds, lastVcoreSeconds, lastGcoreSeconds);
}
示例9: shouldFindReadyForRemindWhenFrequencyIsWeeklyAndLastNotifiedWas8DaysAgo
import org.apache.commons.lang.time.DateUtils; //導入依賴的package包/類
@Test
public void shouldFindReadyForRemindWhenFrequencyIsWeeklyAndLastNotifiedWas8DaysAgo() {
NotificationSettings remind = new NotificationSettings();
remind.setActive(true);
remind.setFrequency(Frequency.WEEKLY);
remind.setLastNotified(DateUtils.addDays(new Date(), -8));
Recipient recipient = new Recipient();
recipient.setAccountName("test");
recipient.setEmail("[email protected]");
recipient.setScheduledNotifications(ImmutableMap.of(
NotificationType.REMIND, remind
));
repository.save(recipient);
List<Recipient> found = repository.findReadyForRemind();
assertFalse(found.isEmpty());
}
示例10: shouldNotFindReadyForRemindWhenFrequencyIsWeeklyAndLastNotifiedWasYesterday
import org.apache.commons.lang.time.DateUtils; //導入依賴的package包/類
@Test
public void shouldNotFindReadyForRemindWhenFrequencyIsWeeklyAndLastNotifiedWasYesterday() {
NotificationSettings remind = new NotificationSettings();
remind.setActive(true);
remind.setFrequency(Frequency.WEEKLY);
remind.setLastNotified(DateUtils.addDays(new Date(), -1));
Recipient recipient = new Recipient();
recipient.setAccountName("test");
recipient.setEmail("[email protected]");
recipient.setScheduledNotifications(ImmutableMap.of(
NotificationType.REMIND, remind
));
repository.save(recipient);
List<Recipient> found = repository.findReadyForRemind();
assertTrue(found.isEmpty());
}
示例11: shouldNotFindReadyForRemindWhenNotificationIsNotActive
import org.apache.commons.lang.time.DateUtils; //導入依賴的package包/類
@Test
public void shouldNotFindReadyForRemindWhenNotificationIsNotActive() {
NotificationSettings remind = new NotificationSettings();
remind.setActive(false);
remind.setFrequency(Frequency.WEEKLY);
remind.setLastNotified(DateUtils.addDays(new Date(), -30));
Recipient recipient = new Recipient();
recipient.setAccountName("test");
recipient.setEmail("[email protected]");
recipient.setScheduledNotifications(ImmutableMap.of(
NotificationType.REMIND, remind
));
repository.save(recipient);
List<Recipient> found = repository.findReadyForRemind();
assertTrue(found.isEmpty());
}
示例12: shouldNotFindReadyForBackupWhenFrequencyIsQuaterly
import org.apache.commons.lang.time.DateUtils; //導入依賴的package包/類
@Test
public void shouldNotFindReadyForBackupWhenFrequencyIsQuaterly() {
NotificationSettings remind = new NotificationSettings();
remind.setActive(true);
remind.setFrequency(Frequency.QUARTERLY);
remind.setLastNotified(DateUtils.addDays(new Date(), -91));
Recipient recipient = new Recipient();
recipient.setAccountName("test");
recipient.setEmail("[email protected]");
recipient.setScheduledNotifications(ImmutableMap.of(
NotificationType.BACKUP, remind
));
repository.save(recipient);
List<Recipient> found = repository.findReadyForBackup();
assertFalse(found.isEmpty());
}
示例13: exec
import org.apache.commons.lang.time.DateUtils; //導入依賴的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;
}
示例14: createReference
import org.apache.commons.lang.time.DateUtils; //導入依賴的package包/類
public static Reference createReference() {
final Reference reference = new Reference();
reference.setSize(REF_BASES_COUNT);
reference.setName("Test.Reference.0.0.1");
reference.setPath("/contents/tests/references/" + reference.getId());
reference.setCreatedDate(DateUtils.truncate(new Date(), Calendar.DAY_OF_MONTH));
reference.setCreatedBy(AuthUtils.getCurrentUserId());
reference.setType(BiologicalDataItemResourceType.FILE);
reference.setIndex(createIndex(BiologicalDataItemFormat.REFERENCE_INDEX,
BiologicalDataItemResourceType.FILE, ""));
final String[] dictionary = new String[]{"A1", "A2", "X"};
for (String name : dictionary) {
final Chromosome chromosome = new Chromosome(name, CHROMOSOME_LENGTH);
chromosome.setPath(String.format("/references/%s/chromosomes/%s/sequences.nib",
reference.getId(), name));
reference.getChromosomes().add(chromosome);
}
return reference;
}
示例15: delAppHistory4index
import org.apache.commons.lang.time.DateUtils; //導入依賴的package包/類
@Override
public int delAppHistory4index(List<Integer> appIds) {
// String hql =
// "delete AppHistory4Index where appStatus=3 and indexStatus=-1 and appId in (:appIds)";
// 刪除前一天生成索引的數據,避免數據過多
String hql = "delete AppHistory4Index where (indexStatus=-1 and appId in (:appIds) ) or lastIndexTime<:lastIndexTime";
Session session = null;
try {
session = this.sessions.openSession();
Query query = session.createQuery(hql);
query.setParameterList("appIds", appIds);
query.setTimestamp("lastIndexTime", DateUtils.addDays(new Date(), -1));// 刪除前一天索引後的數據
return query.executeUpdate();
} catch (Exception e) {
logger.error("error:", e);
return 0;
} finally {
if (session != null && session.isOpen()) {
session.flush();
session.clear();
session.close();
}
}
}