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


Java Duration.getSeconds方法代碼示例

本文整理匯總了Java中java.time.Duration.getSeconds方法的典型用法代碼示例。如果您正苦於以下問題:Java Duration.getSeconds方法的具體用法?Java Duration.getSeconds怎麽用?Java Duration.getSeconds使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.time.Duration的用法示例。


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

示例1: formatAsElapsed

import java.time.Duration; //導入方法依賴的package包/類
public static String formatAsElapsed() {
    Duration elapsed = Duration.ofMillis(ManagementFactory.getRuntimeMXBean().getUptime());
    long days = elapsed.toDays();
    elapsed = elapsed.minusDays(days);
    long hours = elapsed.toHours();
    elapsed = elapsed.minusHours(hours);
    long minutes = elapsed.toMinutes();
    elapsed = elapsed.minusMinutes(minutes);
    long seconds = elapsed.getSeconds();
    elapsed = elapsed.minusSeconds(seconds);
    long millis = elapsed.toMillis();

    return String.format(TIME_FORMAT,
            days,
            hours,
            minutes,
            seconds,
            millis);
}
 
開發者ID:ViniciusArnhold,項目名稱:ProjectAltaria,代碼行數:20,代碼來源:TimeUtils.java

示例2: toCustom

import java.time.Duration; //導入方法依賴的package包/類
public static String toCustom(String format, Duration time) {
    long millis = time.toMillis();
    long seconds = time.getSeconds();
    long minutes = time.toMinutes();
    long hours = time.toHours();
    long days = time.toDays();

    String ms = String.valueOf(millis - (seconds * 1000));
    String s = String.valueOf(seconds - (minutes * 60));
    String m = String.valueOf(minutes - (hours * 60));
    String h = String.valueOf(hours - (days * 24));
    String d = String.valueOf(days);

    if (format.contains("s")) {
        int msCount = StringUtils.countMatches(format, 's');
        ms = ms.substring(0, msCount - 1);
    }

    return format.replace("%D", d).replace("%H", h).replace("%M", m).replace("%S", s).replaceAll("%+s*", ms);
}
 
開發者ID:RedEpicness,項目名稱:RManager,代碼行數:21,代碼來源:CoreUtil.java

示例3: onTick

import java.time.Duration; //導入方法依賴的package包/類
@Override
public void onTick(Duration remaining, Duration total) {
    super.onTick(remaining, total);

    if(this.timeLimit.getShow()) {
        long secondsLeft = remaining.getSeconds();
        if(secondsLeft > 30) {
            if(this.shouldBeep()) {
                this.getMatch().playSound(NOTICE_SOUND);
            }
        }
        else if(secondsLeft > 0) {
            // Tick for the last 30 seconds
            this.getMatch().playSound(IMMINENT_SOUND);
        }
        if(secondsLeft == 5) {
            // Play the portal crescendo sound up to the last moment
            this.getMatch().playSound(CRESCENDO_SOUND);
        }
    }
}
 
開發者ID:OvercastNetwork,項目名稱:ProjectAres,代碼行數:22,代碼來源:TimeLimitCountdown.java

示例4: onTick

import java.time.Duration; //導入方法依賴的package包/類
@Override
@SuppressWarnings("deprecation")
public void onTick(Duration remaining, Duration total) {
    super.onTick(remaining, total);

    if(remaining.getSeconds() >= 1 && remaining.getSeconds() <= 3) {
        // Auto-balance runs at match start as well, but try to run it a few seconds in advance
        if(this.tmm != null && !this.autoBalanced) {
            this.autoBalanced = true;
            this.tmm.balanceTeams();
        }
    }

    if(this.tmm != null && !this.autoBalanced && !this.balanceWarningSent && Comparables.lessOrEqual(remaining, BALANCE_WARNING_TIME)) {
        for(Team team : this.tmm.getTeams()) {
            if(team.isStacked()) {
                this.balanceWarningSent = true;
                this.getMatch().sendWarning(new TranslatableComponent("team.balanceWarning", team.getComponentName()), false);
            }
        }

        if(this.balanceWarningSent) {
            this.getMatch().playSound(COUNT_SOUND);
        }
    }
}
 
開發者ID:OvercastNetwork,項目名稱:ProjectAres,代碼行數:27,代碼來源:StartCountdown.java

示例5: format

import java.time.Duration; //導入方法依賴的package包/類
public String format(Duration object) {
    if (object.isZero()) {
        return "0";
    }
    if (Duration.ofDays(object.toDays()).equals(object)) {
        return object.toDays() + "d";
    }
    if (Duration.ofHours(object.toHours()).equals(object)) {
        return object.toHours() + "h";
    }
    if (Duration.ofMinutes(object.toMinutes()).equals(object)) {
        return object.toMinutes() + "m";
    }
    if (Duration.ofSeconds(object.getSeconds()).equals(object)) {
        return object.getSeconds() + "s";
    }
    if (Duration.ofMillis(object.toMillis()).equals(object)) {
        return object.toMillis() + "ms";
    }
    return object.toNanos() + "ns";
}
 
開發者ID:papyrusglobal,項目名稱:state-channels,代碼行數:22,代碼來源:DurationConverter.java

示例6: beforeEditorTyping

import java.time.Duration; //導入方法依賴的package包/類
@Override
public void beforeEditorTyping(char c, DataContext dataContext) {
    Instant now = Instant.now();
    Duration between = Duration.between(lastInputTime, now);
    lastInputTime = now;

    if (between.getSeconds() < comboCoolTimeSec) {
        comboCount++;
    } else {
        comboCount = 0;
        return;
    }

    RihoReactionNotifier publisher = project.getMessageBus().syncPublisher(RihoReactionNotifier.REACTION_NOTIFIER);
    switch (comboCount) {
        case 5: publisher.reaction(Reaction.of(FacePattern.SMILE1, Duration.ofSeconds(3))); break;
        case 10: publisher.reaction(Reaction.of(FacePattern.SMILE2, Duration.ofSeconds(3))); break;
        case 15: publisher.reaction(Reaction.of(FacePattern.SURPRISE, Duration.ofSeconds(5))); break;
        case 20:
        case 30: publisher.reaction(Reaction.of(FacePattern.AWAWA, Duration.ofSeconds(3))); break;
    }
}
 
開發者ID:orekyuu,項目名稱:Riho,代碼行數:23,代碼來源:IdeActionListener.java

示例7: durationToString

import java.time.Duration; //導入方法依賴的package包/類
public static String durationToString(final Duration duration) {
  final long seconds = duration.getSeconds();
  if (seconds < 0) {
    throw new IllegalArgumentException("negative duration");
  }

  return String.format("%dh%dm%ds",
                       seconds / 3600,
                       (seconds % 3600) / 60,
                       seconds % 60);
}
 
開發者ID:honnix,項目名稱:rkt-launcher,代碼行數:12,代碼來源:Time.java

示例8: getPrettyTime

import java.time.Duration; //導入方法依賴的package包/類
/**
 * Converts the given duration to a string in the format of "x days hh:mm:ss", "hh:mm:ss", or "x seconds",
 * depending on the amount of time in the duration.
 * @param duration The duration to convert to a string.
 * @return The duration as a string.
 */
public static String getPrettyTime(Duration duration) {
    StringBuilder timeString = new StringBuilder();
    long seconds = duration.getSeconds();
    addDays(duration, timeString);
    addHours(duration, timeString, seconds);
    addMinutesAndSeconds(duration, timeString, seconds);
    return timeString.toString();
}
 
開發者ID:ciphertechsolutions,項目名稱:IO,代碼行數:15,代碼來源:Utils.java

示例9: toUnit

import java.time.Duration; //導入方法依賴的package包/類
public static long toUnit(TemporalUnit unit, Duration duration) {
    switch((ChronoUnit) unit) {
        case NANOS:     return duration.toNanos();
        case MICROS:    return toMicros(duration);
        case MILLIS:    return duration.toMillis();
        case SECONDS:   return duration.getSeconds();
    }

    if(unit.getDuration().getNano() == 0) {
        return duration.getSeconds() / unit.getDuration().getSeconds();
    }

    throw new IllegalArgumentException("Unsupported sub-second unit " + unit);
}
 
開發者ID:OvercastNetwork,項目名稱:ProjectAres,代碼行數:15,代碼來源:TimeUtils.java

示例10: updateTimedEvents

import java.time.Duration; //導入方法依賴的package包/類
private void updateTimedEvents() {
    Long now = System.currentTimeMillis();
    Duration timeTick = Duration.ofMillis(now - lastTickSent);
    this.syncProcessor.onTimePassed(timeTick);
    lastTickSent = now;

    //Refresh status to peers every 10 seconds or so
    Duration timeStatus = Duration.ofMillis(now - lastStatusSent);
    if (timeStatus.getSeconds() > 10) {
        sendStatusToAll();
        lastStatusSent = now;
    }
}
 
開發者ID:rsksmart,項目名稱:rskj,代碼行數:14,代碼來源:NodeMessageHandler.java

示例11: convert

import java.time.Duration; //導入方法依賴的package包/類
@Override
protected MongoSession convert(Document sessionWrapper) {

	Object maxInterval = sessionWrapper.getOrDefault(MAX_INTERVAL, this.maxInactiveInterval);

	Duration maxIntervalDuration = (maxInterval instanceof Duration)
		? (Duration) maxInterval
		: Duration.parse(maxInterval.toString());

	MongoSession session = new MongoSession(
		sessionWrapper.getString(ID), maxIntervalDuration.getSeconds());

	Object creationTime = sessionWrapper.get(CREATION_TIME);
	if (creationTime instanceof Instant) {
		session.setCreationTime(((Instant) creationTime).toEpochMilli());
	} else if (creationTime instanceof Date) {
		session.setCreationTime(((Date) creationTime).getTime());
	}

	Object lastAccessedTime = sessionWrapper.get(LAST_ACCESSED_TIME);
	if (lastAccessedTime instanceof Instant) {
		session.setLastAccessedTime((Instant) lastAccessedTime);
	} else if (lastAccessedTime instanceof Date) {
		session.setLastAccessedTime(Instant.ofEpochMilli(((Date) lastAccessedTime).getTime()));
	}

	session.setExpireAt((Date) sessionWrapper.get(EXPIRE_AT_FIELD_NAME));
	
	deserializeAttributes(sessionWrapper, session);

	return session;
}
 
開發者ID:spring-projects,項目名稱:spring-session-data-mongodb,代碼行數:33,代碼來源:JdkMongoSessionConverter.java

示例12: execute

import java.time.Duration; //導入方法依賴的package包/類
@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
	if (args.length == 0 || args.length > 1) {
		throw new WrongUsageException("<Owner>");
	}
	
	ForgePlayer forgePlayer = Universe.get().getPlayer(args[0]);
	
	if (forgePlayer == null) {
		throw new CommandException(String.format("There is no player called %s that has been on this server", args[0]));
	}
	
	ForgeTeam team = forgePlayer.getTeam();
	
	if (team == null) {
		throw new CommandException(String.format("Player %s is not in a team", forgePlayer.getName()));
	}
	
	Set<ClaimedChunk> teamClaimedChunks = ClaimedChunks.get().getTeamChunks(team);
	
	if (teamClaimedChunks.isEmpty()) {
		throw new CommandException(String.format("team %s has not claimed any chunks", team.getName()));
	}
	
	ArrayList<PlayerInChunk> playersInChunks = new ArrayList<PlayerInChunk>();
	for (ClaimedChunk claimedChunk : teamClaimedChunks) {
		ChunkDimPos dimPos = claimedChunk.getPos();
		WorldServer world = FMLCommonHandler.instance().getMinecraftServerInstance().getWorld(dimPos.dim);
		Chunk chunk = world.getChunkFromChunkCoords(dimPos.posX, dimPos.posZ);
		ChunkListOfPlayers chunkListOfPlayers = AllChunks.getChunk(chunk);
		if (chunkListOfPlayers == null) {
			continue;
		}
		
		playersInChunks.addAll(chunkListOfPlayers.playersInChunk);
	}
	
	Collections.sort(playersInChunks, new PlayersInChunkListComparator());
	for (PlayerInChunk player : playersInChunks) {
		String playerName = server.getPlayerProfileCache().getProfileByUUID(player.getPlayer()).getName();
		String enterTime = player.getEnterTimeCalendar().format(DateTimeFormatter.ofPattern("u/M/d H:m:s"));
		if (player.hasLeft()) {
			String leaveTime = player.getLeaveTimeCalendar().format(DateTimeFormatter.ofPattern("u/M/d H:m:s"));
			Duration stayTime = player.getStayTime();
			Long years = stayTime.toDays() / 365L;
			Long months = stayTime.toDays() / 30L;
			Long days = stayTime.toDays();
			Long hours = stayTime.toHours();
			Long minutes = stayTime.toMinutes();
			Long seconds = stayTime.getSeconds();
			if (months > 11) {
				months = months - (years * 12);
			}
			if (days > 29) {
				days = days - (days / 30 * 30);
			}
			if (hours > 23) {
				hours = hours - (hours / 24 * 24);
			}
			if (minutes > 59) {
				minutes = minutes - (minutes / 60 * 60);
			}
			if (seconds > 59) {
				seconds = seconds - (seconds / 60 * 60);
			}
			sender.sendMessage(new TextComponentString(String.format("Player %s was in one of the chunks from %s to %s for %s years and %s months and %s days and %s hours and %s minutes and %s seconds.", playerName, enterTime, leaveTime, years, months, days, hours, minutes, seconds)));
		} else {
			sender.sendMessage(new TextComponentString(String.format("Player %s was in one of the chunks from %s and has not left yet", playerName, enterTime)));
		}
	}
}
 
開發者ID:coehlrich,項目名稱:chunk-logger,代碼行數:72,代碼來源:GetPlayersInClaimedChunks.java

示例13: LongRunningMessageHandler

import java.time.Duration; //導入方法依賴的package包/類
LongRunningMessageHandler(@NonNull ScheduledExecutorService timeoutExtensionExecutor,
        int maxNumberOfMessages, int numberOfThreads,
        @NonNull MessageHandlingRunnableFactory messageHandlingRunnableFactory,
        @NonNull VisibilityTimeoutExtenderFactory timeoutExtenderFactory,
        @NonNull MessageWorkerWithHeaders<I, O> worker, @NonNull Queue queue,
        @NonNull FinishedMessageCallback<I, O> finishedMessageCallback,
        @NonNull Duration timeUntilVisibilityTimeoutExtension,
        @NonNull Duration awaitShutDown) {
    if (timeUntilVisibilityTimeoutExtension.isZero() || timeUntilVisibilityTimeoutExtension
            .isNegative()) {
        throw new IllegalArgumentException("the timeout has to be > 0");
    }
    this.timeoutExtensionExecutor = timeoutExtensionExecutor;
    this.messageHandlingRunnableFactory = messageHandlingRunnableFactory;
    this.timeoutExtenderFactory = timeoutExtenderFactory;
    this.worker = worker;
    this.queue = queue;
    this.finishedMessageCallback = finishedMessageCallback;
    this.timeUntilVisibilityTimeoutExtension = timeUntilVisibilityTimeoutExtension;

    messageProcessingExecutor = new ThreadPoolTaskExecutor();
    messageProcessingExecutor.setMaxPoolSize(numberOfThreads);
    messageProcessingExecutor.setCorePoolSize(numberOfThreads);
    /*
     * Since we only accept new messages if one slot in the messagesInProcessing-Set
     * / executor is free we can schedule at least one message for instant execution
     * while (maxNumberOfMessages - 1) will be put into the queue
     */
    messageProcessingExecutor.setQueueCapacity(maxNumberOfMessages - 1);
    messageProcessingExecutor.setAwaitTerminationSeconds((int) awaitShutDown.getSeconds());
    if (awaitShutDown.getSeconds() > 0) {
        Runtime.getRuntime().addShutdownHook(new Thread(messageProcessingExecutor::shutdown));
    }
    messageProcessingExecutor.afterPropertiesSet();

    messagesInProcessing = new SetWithUpperBound<>(numberOfThreads);

    if (queue.getDefaultVisibilityTimeout().minusSeconds(5).compareTo(
            timeUntilVisibilityTimeoutExtension) < 0) {
        throw new IllegalStateException("The extension interval of "
                + timeUntilVisibilityTimeoutExtension.getSeconds()
                + " is too close to the VisibilityTimeout of " + queue
                        .getDefaultVisibilityTimeout().getSeconds()
                + " seconds of the queue, has to be at least 5 seconds less.");
    }
}
 
開發者ID:Mercateo,項目名稱:sqs-utils,代碼行數:47,代碼來源:LongRunningMessageHandler.java

示例14: toMultiText

import java.time.Duration; //導入方法依賴的package包/類
public static String toMultiText(Duration time, boolean isShort) {
    long millis = time.toMillis();
    long seconds = time.getSeconds();
    long minutes = time.toMinutes();
    long hours = time.toHours();
    long days = time.toDays();

    millis = millis - (seconds * 1000);
    seconds = seconds - (minutes * 60);
    minutes = minutes - (hours * 60);
    hours = hours - (days * 24);

    StringBuilder builder = new StringBuilder();

    if (days != 0) {
        builder.append(days);
        if (isShort) builder.append("d");
        else builder.append(" Days");
    }
    if (hours != 0) {
        builder.append(" ");
        builder.append(hours);
        if (isShort) builder.append("h");
        else builder.append(" Hours");
    }
    if (minutes != 0) {
        builder.append(" ");
        builder.append(minutes);
        if (isShort) builder.append("m");
        else builder.append(" Minutes");
    }
    if (seconds != 0) {
        builder.append(" ");
        builder.append(seconds);
        if (isShort) builder.append("s");
        else builder.append(" Seconds");
    }
    if (millis != 0) {
        builder.append(" ");
        builder.append(millis);
        if (isShort) builder.append("ms");
        else builder.append(" Milliseconds");
    }

    return builder.toString().trim();
}
 
開發者ID:RedEpicness,項目名稱:RManager,代碼行數:47,代碼來源:CoreUtil.java

示例15: getMinutes

import java.time.Duration; //導入方法依賴的package包/類
private static long getMinutes(Duration duration){
	Long totalSecs = duration.getSeconds();
	return (totalSecs % HOUER_CONVERTION) / SECOND_CONVERSION;
}
 
開發者ID:erikns,項目名稱:webpoll,代碼行數:5,代碼來源:DurationFormatter.java


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