本文整理汇总了Java中java.time.Duration.toMinutes方法的典型用法代码示例。如果您正苦于以下问题:Java Duration.toMinutes方法的具体用法?Java Duration.toMinutes怎么用?Java Duration.toMinutes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.time.Duration
的用法示例。
在下文中一共展示了Duration.toMinutes方法的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);
}
示例2: 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";
}
示例3: readableDuration
import java.time.Duration; //导入方法依赖的package包/类
public static String readableDuration(Duration uptime) {
long seconds = uptime.get(ChronoUnit.SECONDS);
if(seconds < 60) {
return seconds+" sec";
} else {
long minutes = uptime.toMinutes();
if(minutes < 60) {
return minutes+" min";
} else {
long hours = uptime.toHours();
if(hours < 24) {
return hours +" hours";
}
else {
long days = uptime.toDays();
return days + " days";
}
}
}
}
示例4: 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);
}
示例5: addMinutesAndSeconds
import java.time.Duration; //导入方法依赖的package包/类
private static void addMinutesAndSeconds(Duration duration, StringBuilder timeString, long seconds) {
if (duration.toMinutes() >= 1) {
int remainingMinutes = (int) ((seconds % 3600) / 60);
padIfNeeded(timeString, remainingMinutes);
timeString.append(":");
int remainingSeconds = (int) (seconds % 60);
padIfNeeded(timeString, remainingSeconds);
}
else {
timeString.append(seconds % 60);
timeString.append(" seconds.");
}
}
示例6: toMMSS
import java.time.Duration; //导入方法依赖的package包/类
public static String toMMSS(Duration time) {
long seconds = time.getSeconds();
long minutes = time.toMinutes();
String s = (seconds - (minutes * 60)) + "";
if (s.length() < 2) s = "0" + s;
return (minutes < 10 ? "0" + minutes : minutes) + ":" + s; //MM:SS
}
示例7: timeSince
import java.time.Duration; //导入方法依赖的package包/类
private static Function<Instant, Text> timeSince(final Locale locale) {
return (instant -> {
Text text = Text.of(DateTimeFormatter.ofLocalizedDateTime(FormatStyle.MEDIUM)
.withLocale(locale)
.withZone(ZoneId.systemDefault())
.format(instant));
String str = instant.compareTo(Instant.now()) < 0 ? " (%s %s from now)" : " (%s %s ago)";
Duration dur = Duration.between(instant, Instant.now());
if (dur.getSeconds() < 1)
return text.concat(Text.of(" (Now)"));
// seconds
if (dur.getSeconds() < 60)
return text.concat(Text.of(String.format(str, dur.getSeconds(), "seconds")));
// minutes
if (dur.toMinutes() < 60)
return text.concat(Text.of(" (" + dur.toMinutes() + " minutes ago)"));
// hours
if (dur.toHours() < 24)
return text.concat(Text.of(" (" + dur.toHours() + " hours ago)"));
// days
if (dur.toDays() < 365)
return text.concat(Text.of(" (" + dur.toDays() + " days ago)"));
// Duration doesn't support months or years
Period per = Period.between(LocalDate.from(instant), LocalDate.now());
// months
if (per.getMonths() < 12) {
return text.concat(Text.of(" (" + per.getMonths() + " months ago)"));
}
// years
return text.concat(Text.of(" (" + per.getYears() + " years ago)"));
});
}
示例8: convertMicrosecondsToTimeString
import java.time.Duration; //导入方法依赖的package包/类
/**
* Convert microseconds to a human readable time string.
*
* @param microseconds The amount of microseconds.
* @return The human readable string representation.
*/
public static String convertMicrosecondsToTimeString(final long microseconds) {
Duration durationMilliseconds = Duration.ofMillis(microseconds / MICROSECOND_FACTOR);
long minutes = durationMilliseconds.toMinutes();
long seconds = durationMilliseconds.minusMinutes(minutes).getSeconds();
long milliseconds = durationMilliseconds.minusMinutes(minutes).minusSeconds(seconds).toMillis();
return String.format("%dm %02ds %03dms", minutes, seconds, milliseconds);
}
示例9: format
import java.time.Duration; //导入方法依赖的package包/类
public static long format(Duration duration) {
Objects.requireNonNull(duration, FORMATTED_OBJECTS_ISNT_ALLOWED_TO_BE_NULL);
return duration.toMinutes();
}
示例10: check
import java.time.Duration; //导入方法依赖的package包/类
@Override
public boolean check(String login, String password) {
//TODO FAILED LOGIN Counter Rule
if (failedLogins.containsKey(login)) {
Pair<LocalDateTime, Integer> pair = failedLogins.get(login);
LocalDateTime failedLoginDate = pair.getT1();
Integer failedLoginCount = pair.getT2();
if (failedLoginCount > MAX_FAILED_LOGINS) {
LOGGER.debug("failedLoginCount > MAX_FAILED_LOGINS " + failedLoginCount);
final Duration duration = between(failedLoginDate, LocalDateTime.now());
long minutes = duration.toMinutes();
if (minutes > MINUTES_TO_WAIT) {
LOGGER.debug("minutes > MINUTES_TO_WAIT (remove login) " + failedLoginCount);
failedLogins.remove(login); // start from zero
} else {
LOGGER.debug("failedLoginCount <= MAX_FAILED_LOGINS " + failedLoginCount);
failedLogins.compute(
login,
(s, faildPair) -> new Pair<>(LocalDateTime.now(), failedLoginCount + 1));
return false;
}
} else {
LOGGER.debug("failedLoginCount => " + login + " - " + failedLoginCount);
}
}
final UsernamePasswordToken token = new UsernamePasswordToken(login, password);
final Subject subject = SecurityUtils.getSubject();
try {
subject.login(token);
printInfos(subject);
failedLogins.remove(login);
} catch (AuthenticationException e) {
LOGGER.debug("login failed " + login);
//e.printStackTrace();
failedLogins.putIfAbsent(login, new Pair<>(LocalDateTime.now(), 0));
failedLogins.compute(
login,
(s, oldPair) -> new Pair<>(LocalDateTime.now(), oldPair.getT2() + 1));
}
return subject.isAuthenticated();
}
示例11: 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();
}
示例12: ZetDuur_id3CWQViUPQ1p
import java.time.Duration; //导入方法依赖的package包/类
static void ZetDuur_id3CWQViUPQ1p(@NotNull SNode __thisNode__, Duration duration) {
Long duur = duration.toMinutes();
SPropertyOperations.set(__thisNode__, MetaAdapterFactory.getProperty(0x61be2dc6a1404defL, 0xa5927499aa2bac19L, 0x46db587183b2cdc8L, 0x46db587183b2cdc9L, "minuten"), duur.toString());
}
示例13: ZetDuur_id3CWQViUPQ1p
import java.time.Duration; //导入方法依赖的package包/类
static void ZetDuur_id3CWQViUPQ1p(@NotNull SNode __thisNode__, Duration duration) {
Long duur = duration.toMinutes();
duur = duur * 60;
SPropertyOperations.set(__thisNode__, MetaAdapterFactory.getProperty(0x61be2dc6a1404defL, 0xa5927499aa2bac19L, 0x46db587183b32322L, 0x46db587183b32323L, "seconden"), duur.toString());
}
示例14: 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)));
}
}
}
示例15: execute
import java.time.Duration; //导入方法依赖的package包/类
@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
if (args.length < 2 || args.length > 3) {
throw new WrongUsageException("<ChunkX> <ChunkZ> [dimensionID]");
}
int chunkX = Integer.parseInt(args[0]);
int chunkZ = Integer.parseInt(args[1]);
int dimensionID;
if (args.length < 3) {
dimensionID = 0;
} else {
dimensionID = Integer.parseInt(args[2]);
}
ArrayList<Integer> dimensionids = new ArrayList<Integer>();
dimensionids.toArray(DimensionManager.getIDs());
int dimensionid;
if (args.length == 3) {
if (!dimensionids.contains(Integer.parseInt(args[2]))) {
throw new NumberInvalidException("Dimension ID " + args[2] + " does not exist");
} else {
dimensionid = Integer.parseInt(args[2]);
}
} else {
dimensionid = 0;
}
Chunk chunk = new Chunk(FMLCommonHandler.instance().getMinecraftServerInstance().getWorld(dimensionid), chunkX, chunkZ);
ChunkListOfPlayers chunkListOfPlayers = AllChunks.getChunk(chunk);
if (chunkListOfPlayers == null) {
sender.sendMessage(new TextComponentString("Noone has been in that chunk yet"));
return;
}
ArrayList<PlayerInChunk> playersInChunk = (ArrayList<PlayerInChunk>) chunkListOfPlayers.getPlayersInChunk().clone();
for (PlayerInChunk player : playersInChunk) {
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 the chunk 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 the chunk from %s and has not left yet", playerName, enterTime)));
}
}
}