當前位置: 首頁>>代碼示例>>Java>>正文


Java DurationFormatUtils類代碼示例

本文整理匯總了Java中org.apache.commons.lang.time.DurationFormatUtils的典型用法代碼示例。如果您正苦於以下問題:Java DurationFormatUtils類的具體用法?Java DurationFormatUtils怎麽用?Java DurationFormatUtils使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


DurationFormatUtils類屬於org.apache.commons.lang.time包,在下文中一共展示了DurationFormatUtils類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getAge

import org.apache.commons.lang.time.DurationFormatUtils; //導入依賴的package包/類
public static String getAge(long value) {
	long currentTime = (new Date()).getTime();
	long age = currentTime - value;
	String ageString = DurationFormatUtils.formatDuration(age, "d") + "d";
	if ("0d".equals(ageString)) {
		ageString = DurationFormatUtils.formatDuration(age, "H") + "h";
		if ("0h".equals(ageString)) {
			ageString = DurationFormatUtils.formatDuration(age, "m") + "m";
			if ("0m".equals(ageString)) {
				ageString = DurationFormatUtils.formatDuration(age, "s") + "s";
				if ("0s".equals(ageString)) {
					ageString = age + "ms";
				}
			}
		}
	}
	return ageString;
}
 
開發者ID:ibissource,項目名稱:iaf,代碼行數:19,代碼來源:Misc.java

示例2: titaniumKitGlass

import org.apache.commons.lang.time.DurationFormatUtils; //導入依賴的package包/類
private ItemStack titaniumKitGlass(Player player) {
	ItemStack stack = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 0, (byte) 14);
	ItemMeta meta = stack.getItemMeta();
	addGlow(stack);
	meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', "&4Titanium &7Kit"));
	List<String> lore = new ArrayList<String>();
	lore.add(ChatColor.translateAlternateColorCodes('&', "&7This is a kit contains:"));
	lore.add(ChatColor.translateAlternateColorCodes('&', "&fGod Diamond kit!"));
	lore.add("");
	lore.add(ChatColor.translateAlternateColorCodes('&', "&8&l* &cPurchase the Titanium Rank from store.hcriots.net"));
	lore.add("");
	lore.add(ChatColor.translateAlternateColorCodes('&', "&8&l* &7CoolDown: &c3 Days"));
	if(cooldowns.containsKey(player.getUniqueId())) {
		if(cooldowns.get(player.getUniqueId()).containsKey("TitaniumKit")) {
			lore.add(ChatColor.translateAlternateColorCodes('&', "&8&l* &7Available in: &c" + DurationFormatUtils.formatDurationWords(cooldowns.get(player.getUniqueId()).get("TitaniumKit"), true, true)));
		} else {
			lore.add(ChatColor.translateAlternateColorCodes('&', "&8&l* &7Available in: &aNow"));
		}
	} else {
		lore.add(ChatColor.translateAlternateColorCodes('&', "&8&l* &7Available in: &aNow"));
	}
	meta.setLore(lore);
	stack.setItemMeta(meta);
	return stack;
}
 
開發者ID:funkemunky,項目名稱:HCFCore,代碼行數:26,代碼來源:KitsCommand.java

示例3: diamondKitGlass

import org.apache.commons.lang.time.DurationFormatUtils; //導入依賴的package包/類
private ItemStack diamondKitGlass(Player player) {
	ItemStack stack = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 0, (byte) 9);
	ItemMeta meta = stack.getItemMeta();
	addGlow(stack);
	meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', "&bDiamond &7Kit"));
	List<String> lore = new ArrayList<String>();
	lore.add(ChatColor.translateAlternateColorCodes('&', "&7This kit contains:"));
	lore.add(ChatColor.translateAlternateColorCodes('&', "&fGod Diamond kit with Looting!"));
	lore.add("");
	lore.add(ChatColor.translateAlternateColorCodes('&', "&8&l* &cPurchase this from store.hcriots.net"));
	lore.add("");
	lore.add(ChatColor.translateAlternateColorCodes('&', "&8&l* &7CoolDown: &c3 Days"));
	if(cooldowns.containsKey(player.getUniqueId())) {
		if(cooldowns.get(player.getUniqueId()).containsKey("DiamondKit")) {
			lore.add(ChatColor.translateAlternateColorCodes('&', "&8&l* &7Available in: &c" + DurationFormatUtils.formatDurationWords(cooldowns.get(player.getUniqueId()).get("DiamondKit"), true, true)));
		} else {
			lore.add(ChatColor.translateAlternateColorCodes('&', "&8&l* &7Available in: &aNow"));
		}
	} else {
		lore.add(ChatColor.translateAlternateColorCodes('&', "&8&l* &7Available in: &aNow"));
	}
	meta.setLore(lore);
	stack.setItemMeta(meta);
	return stack;
}
 
開發者ID:funkemunky,項目名稱:HCFCore,代碼行數:26,代碼來源:KitsCommand.java

示例4: bardKitGlass

import org.apache.commons.lang.time.DurationFormatUtils; //導入依賴的package包/類
private ItemStack bardKitGlass(Player player) {
	ItemStack stack = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 0, (byte) 4);
	ItemMeta meta = stack.getItemMeta();
	addGlow(stack);
	meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', "&eBard &7Kit"));
	List<String> lore = new ArrayList<String>();
	lore.add(ChatColor.translateAlternateColorCodes('&', "&7This kit contains:"));
	lore.add(ChatColor.translateAlternateColorCodes('&', "&fGod Bard kit with Bard Materials!"));
	lore.add("");
	lore.add(ChatColor.translateAlternateColorCodes('&', "&8&l* &cPurchase this from store.hcriots.net"));
	lore.add("");
	lore.add(ChatColor.translateAlternateColorCodes('&', "&8&l* &7CoolDown: &c3 Days"));
	if(cooldowns.containsKey(player.getUniqueId())) {
		if(cooldowns.get(player.getUniqueId()).containsKey("BardKit")) {
			lore.add(ChatColor.translateAlternateColorCodes('&', "&8&l* &7Available in: &c" + DurationFormatUtils.formatDurationWords(cooldowns.get(player.getUniqueId()).get("BardKit"), true, true)));
		} else {
			lore.add(ChatColor.translateAlternateColorCodes('&', "&8&l* &7Available in: &aNow"));
		}
	} else {
		lore.add(ChatColor.translateAlternateColorCodes('&', "&8&l* &7Available in: &aNow"));
	}
	meta.setLore(lore);
	stack.setItemMeta(meta);
	return stack;
}
 
開發者ID:funkemunky,項目名稱:HCFCore,代碼行數:26,代碼來源:KitsCommand.java

示例5: archerKitGlass

import org.apache.commons.lang.time.DurationFormatUtils; //導入依賴的package包/類
private ItemStack archerKitGlass(Player player) {
	ItemStack stack = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 0, (byte) 6);
	ItemMeta meta = stack.getItemMeta();
	addGlow(stack);
	meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', "&dArcher &7Kit"));
	List<String> lore = new ArrayList<String>();
	lore.add(ChatColor.translateAlternateColorCodes('&', "&7This kit contains:"));
	lore.add(ChatColor.translateAlternateColorCodes('&', "&fGod Archer kit with Archer Materials!"));
	lore.add("");
	lore.add(ChatColor.translateAlternateColorCodes('&', "&8&l* &cPurchase this from store.hcriots.net"));
	lore.add("");
	lore.add(ChatColor.translateAlternateColorCodes('&', "&8&l* &7CoolDown: &c3 Days"));
	if(cooldowns.containsKey(player.getUniqueId())) {
		if(cooldowns.get(player.getUniqueId()).containsKey("ArcherKit")) {
			lore.add(ChatColor.translateAlternateColorCodes('&', "&8&l* &7Available in: &c" + DurationFormatUtils.formatDurationWords(cooldowns.get(player.getUniqueId()).get("ArcherKit"), true, true)));
		} else {
			lore.add(ChatColor.translateAlternateColorCodes('&', "&8&l* &7Available in: &aNow"));
		}
	} else {
		lore.add(ChatColor.translateAlternateColorCodes('&', "&8&l* &7Available in: &aNow"));
	}
	meta.setLore(lore);
	stack.setItemMeta(meta);
	return stack;
}
 
開發者ID:funkemunky,項目名稱:HCFCore,代碼行數:26,代碼來源:KitsCommand.java

示例6: minerKitGlass

import org.apache.commons.lang.time.DurationFormatUtils; //導入依賴的package包/類
private ItemStack minerKitGlass(Player player) {
	ItemStack stack = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 0, (byte) 6);
	ItemMeta meta = stack.getItemMeta();
	addGlow(stack);
	meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', "&9Miner &7Kit"));
	List<String> lore = new ArrayList<String>();
	lore.add(ChatColor.translateAlternateColorCodes('&', "&7This kit contains:"));
	lore.add(ChatColor.translateAlternateColorCodes('&', "&fGod Miner Set with Diamond Pickaxe and Anvils!"));
	lore.add("");
	lore.add(ChatColor.translateAlternateColorCodes('&', "&8&l* &cPurchase this from store.hcriots.net"));
	lore.add("");
	lore.add(ChatColor.translateAlternateColorCodes('&', "&8&l* &7CoolDown: &c3 Days"));
	if(cooldowns.containsKey(player.getUniqueId())) {
		if(cooldowns.get(player.getUniqueId()).containsKey("ArcherKit")) {
			lore.add(ChatColor.translateAlternateColorCodes('&', "&8&l* &7Available in: &c" + DurationFormatUtils.formatDurationWords(cooldowns.get(player.getUniqueId()).get("ArcherKit"), true, true)));
		} else {
			lore.add(ChatColor.translateAlternateColorCodes('&', "&8&l* &7Available in: &aNow"));
		}
	} else {
		lore.add(ChatColor.translateAlternateColorCodes('&', "&8&l* &7Available in: &aNow"));
	}
	meta.setLore(lore);
	stack.setItemMeta(meta);
	return stack;
}
 
開發者ID:funkemunky,項目名稱:HCFCore,代碼行數:26,代碼來源:KitsCommand.java

示例7: starterKitGlass

import org.apache.commons.lang.time.DurationFormatUtils; //導入依賴的package包/類
private ItemStack starterKitGlass(Player player) {
	ItemStack stack = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 0, (byte) 13);
	ItemMeta meta = stack.getItemMeta();
	addGlow(stack);
	meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', "&fStarter &7Kit"));
	List<String> lore = new ArrayList<String>();
	lore.add(ChatColor.translateAlternateColorCodes('&', "&7This kit contains:"));
	lore.add(ChatColor.translateAlternateColorCodes('&', "&fLeather Set with an Iron Sword, Iron Pickaxe, and Food!"));
	lore.add("");
	lore.add(ChatColor.translateAlternateColorCodes('&', "&8&l* &cPurchase this from store.hcriots.net"));
	lore.add("");
	lore.add(ChatColor.translateAlternateColorCodes('&', "&8&l* &7CoolDown: &c3 Days"));
	if(cooldowns.containsKey(player.getUniqueId())) {
		if(cooldowns.get(player.getUniqueId()).containsKey("StarterKit")) {
			lore.add(ChatColor.translateAlternateColorCodes('&', "&8&l* &7Available in: &c" + DurationFormatUtils.formatDurationWords(cooldowns.get(player.getUniqueId()).get("StarterKit"), true, true)));
		} else {
			lore.add(ChatColor.translateAlternateColorCodes('&', "&8&l* &7Available in: &aNow"));
		}
	} else {
		lore.add(ChatColor.translateAlternateColorCodes('&', "&8&l* &7Available in: &aNow"));
	}
	meta.setLore(lore);
	stack.setItemMeta(meta);
	return stack;
}
 
開發者ID:funkemunky,項目名稱:HCFCore,代碼行數:26,代碼來源:KitsCommand.java

示例8: computeDeadlineAsString

import org.apache.commons.lang.time.DurationFormatUtils; //導入依賴的package包/類
private String computeDeadlineAsString(PageBase page) {
    XMLGregorianCalendar deadline = certCase.getCurrentStageDeadline();

    if (deadline == null) {
        return "";
    } else {
        long delta = XmlTypeConverter.toMillis(deadline) - System.currentTimeMillis();

        // round to hours; we always round down
        long precision = 3600000L;      // 1 hour
        if (Math.abs(delta) > precision) {
            delta = (delta / precision) * precision;
        }

        //todo i18n
        if (delta > 0) {
        	return PageBase.createStringResourceStatic(page, "PageCert.in", DurationFormatUtils.formatDurationWords(delta, true, true)).getString();
        } else if (delta < 0) {
        	return PageBase.createStringResourceStatic(page, "PageCert.ago", DurationFormatUtils.formatDurationWords(-delta, true, true)).getString();
        } else {
            return page.getString("PageCert.now");
        }
    }
}
 
開發者ID:Pardus-Engerek,項目名稱:engerek,代碼行數:25,代碼來源:CertCaseOrWorkItemDto.java

示例9: getValueAt

import org.apache.commons.lang.time.DurationFormatUtils; //導入依賴的package包/類
@Override
public Object getValueAt(int rowIndex, int columnIndex) {
    Defense elem = entries.get(rowIndex);
    switch (columnIndex) {
        case 0:
            return elem.getSupporter();
        case 1:
            return elem.getTarget();
        case 2:
            return new Date(elem.getBestSendTime());
        case 3:
            return new Date(elem.getWorstSendTime());
        case 4:

            long sendTime = elem.getBestSendTime();
            if (sendTime < System.currentTimeMillis()) {//if best in past, take worst
                sendTime = elem.getWorstSendTime();
            }
            long t = sendTime - System.currentTimeMillis();
            t = (t <= 0) ? 0 : t;
            return DurationFormatUtils.formatDuration(t, "HHH:mm:ss.SSS", true);
        default:
            return elem.isTransferredToBrowser();
    }
}
 
開發者ID:Torridity,項目名稱:dsworkbench,代碼行數:26,代碼來源:SupportsModel.java

示例10: destroy

import org.apache.commons.lang.time.DurationFormatUtils; //導入依賴的package包/類
/**
 * Destroys this batch.
 */
public void destroy() {
    logger.trace("{} - Destroy called on Batch", name);
    scheduler.shutdown();

    try {
        if (!scheduler.awaitTermination(maxAwaitTimeShutdown, TimeUnit.MILLISECONDS)) {
            logger.warn(
                    "Could not terminate batch within {}. Forcing shutdown.",
                    DurationFormatUtils.formatDurationWords(
                            maxAwaitTimeShutdown,
                            true,
                            true
                    )
            );
            scheduler.shutdownNow();
        }
    } catch (final InterruptedException e) {
        Thread.currentThread().interrupt();
        logger.debug("Interrupted while waiting.", e);
    }

    flush();
}
 
開發者ID:feedzai,項目名稱:pdb,代碼行數:27,代碼來源:AbstractBatch.java

示例11: getQueueFirstMessageAgeAsString

import org.apache.commons.lang.time.DurationFormatUtils; //導入依賴的package包/類
protected static String getQueueFirstMessageAgeAsString(Session jSession,
		String queueName, long currentTime) {
	try {
		long age = getQueueFirstMessageAge(jSession, queueName, null,
				currentTime, false);
		if (age == -2) {
			return "??";
		} else if (age == -1) {
			return null;
		} else {
			return DurationFormatUtils.formatDuration(age, "ddd-HH:mm:ss");
		}
	} catch (JMSException e) {
		return "?";
	}
}
 
開發者ID:ibissource,項目名稱:iaf,代碼行數:17,代碼來源:TibcoUtils.java

示例12: toString

import org.apache.commons.lang.time.DurationFormatUtils; //導入依賴的package包/類
/**
 * output as:
 * 551			150			1000		0:00:01.701
 * step1(ms)	step2(ms)	step3(ms)	total duration
 */
@Override
public String toString() {
	long currentTimeMillis = System.currentTimeMillis();
	if(stops!=null && stops.size()>0){
		List<Long> durationList = new ArrayList<Long>();
		long last = this.startTime;
		for(int i=0;i<stops.size();i++){
			long cur = stops.get(i);
durationList.add(cur - last);
last = cur;
		}
		if (this.running) {
durationList.add(currentTimeMillis - last);
     } else {
     	durationList.add(this.stopTime - last);
     }
		
		return StringUtils.join(durationList, "\t")+"\t"+DurationFormatUtils.formatDurationHMS(getTime(currentTimeMillis));
	}else{
		return DurationFormatUtils.formatDurationHMS(getTime(currentTimeMillis));
	}
}
 
開發者ID:houdejun214,項目名稱:lakeside-java,代碼行數:28,代碼來源:StopWatch.java

示例13: displayStats

import org.apache.commons.lang.time.DurationFormatUtils; //導入依賴的package包/類
private void displayStats(long insertedCnt) {
    float percentComplete = (float) insertedCnt / (float) rowCnt;
    long now = System.currentTimeMillis();
    long elapsedTime = now - startTime;
    long timeRemaining = ((long) (((float) (now - startTime)) / percentComplete)) - elapsedTime;
    String elapsedTimeStr = DurationFormatUtils.formatDurationWords(elapsedTime, true, true);
    String timeRemainingStr = DurationFormatUtils.formatDurationWords(timeRemaining, true,
                                                                      true);

    System.out.println("Inserted " + insertedCnt + " rows (" + readyToFindCnt + " readyToFind, "
            + readyToProcessCnt + " readyToProcess, " + readyToPostProcessCnt
            + " readyToPostProcess) in " + elapsedTimeStr + ".  "
            + ((int) (percentComplete * 100)) + " % complete, " + timeRemainingStr
            + " remaining.");
}
 
開發者ID:Hitachi-Data-Systems,項目名稱:Open-DM,代碼行數:16,代碼來源:PopulateDmDb.java

示例14: getTimeMonitorThread

import org.apache.commons.lang.time.DurationFormatUtils; //導入依賴的package包/類
/**
 * Returns a thread which executes the provided command if the system clock moves forward or backwards by the
 * threshold specified.
 *
 * @param timeChangeCommand
 *            the command to run when system clock is changed
 * @param timeChangeThreshold
 *            the time difference in millisecs that the caller can adjust for, if the time changes by
 *            more than this amount, the time change command will be executed.
 * @param sleepInterval
 *            the amount of time the thread sleeps before it checks to see if system clock was changed
 *
 * @return the thread which the caller can decide to start
 */
public static Thread getTimeMonitorThread(final TimeChangeCommand timeChangeCommand, final long timeChangeThreshold,
        final long sleepInterval) {
    Runnable timeMonitorThread = new Runnable() {

        private long previousTime = new Date().getTime();

        @Override
        public void run() {
            while (true) {
                long currentTime = new Date().getTime();
                long timeDifference = currentTime - (this.previousTime + sleepInterval);
                if (timeDifference >= timeChangeThreshold || timeDifference <= -timeChangeThreshold) {
                    String timeDifferenceString = DurationFormatUtils.formatDuration(Math.abs(timeDifference),
                            "d 'Days' H 'Hours' m 'Minutes' s 'Seconds'");
                    log.warn(String.format(
                            "System Time change detected. Time shift: %s Current Time: %s  Previous Time: %s",
                            timeDifferenceString, new Date(currentTime), new Date(this.previousTime)));
                    timeChangeCommand.execute(timeDifference);
                }
                this.previousTime = currentTime;

                try {
                    Thread.sleep(sleepInterval);
                } catch (InterruptedException e) {
                    log.info("Time monitor thread interrupted. Ignoring...");
                }
            }
        }
    };

    return new Thread(timeMonitorThread, "Time-Monitor-Thread");
}
 
開發者ID:opensecuritycontroller,項目名稱:osc-core,代碼行數:47,代碼來源:ServerUtil.java

示例15: shouldDefer

import org.apache.commons.lang.time.DurationFormatUtils; //導入依賴的package包/類
private boolean shouldDefer() {
  /* If revocationTimeMs == 0, this is an immediate uncache request.
   * No clients were anchored at the time we made the request. */
  if (revocationTimeMs == 0) {
    return false;
  }
  /* Let's check if any clients still have this block anchored. */
  boolean anchored =
    !dataset.datanode.getShortCircuitRegistry().
        processBlockMunlockRequest(key);
  if (!anchored) {
    LOG.debug("Uncaching {} now that it is no longer in use " +
        "by any clients.", key);
    return false;
  }
  long delta = revocationTimeMs - Time.monotonicNow();
  if (delta < 0) {
    LOG.warn("Forcibly uncaching {} after {} " +
        "because client(s) {} refused to stop using it.", key,
        DurationFormatUtils.formatDurationHMS(revocationTimeMs),
        dataset.datanode.getShortCircuitRegistry().getClientNames(key));
    return false;
  }
  LOG.info("Replica {} still can't be uncached because some " +
      "clients continue to use it.  Will wait for {}", key,
      DurationFormatUtils.formatDurationHMS(delta));
  return true;
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:29,代碼來源:FsDatasetCache.java


注:本文中的org.apache.commons.lang.time.DurationFormatUtils類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。