本文整理汇总了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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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");
}
}
}
示例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();
}
}
示例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();
}
示例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 "?";
}
}
示例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));
}
}
示例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.");
}
示例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");
}
示例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;
}