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


Java Duration.toDays方法代碼示例

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


在下文中一共展示了Duration.toDays方法的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: 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

示例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";
			}
		}
	}
}
 
開發者ID:vianneyfaivre,項目名稱:Persephone,代碼行數:22,代碼來源:Formatters.java

示例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);
}
 
開發者ID:RedEpicness,項目名稱:RManager,代碼行數:21,代碼來源:CoreUtil.java

示例5: durationInMillisToString

import java.time.Duration; //導入方法依賴的package包/類
private static String durationInMillisToString(Duration duration) {
	long days = duration.toDays(); // chop off any days as formatter can't handle them
	duration = duration.minusDays(days);

	// convert duration to a time by adding it to midnight
	LocalTime durationAsTime = LocalTime.MIDNIGHT.plus(duration);
	String result = formatter.format(durationAsTime);

	if (days > 0) result = String.format("%dd ", days) + result;
	return result;
}
 
開發者ID:eclipse,項目名稱:scanning,代碼行數:12,代碼來源:SolsticeScanMonitor.java

示例6: updateUnitsToPrint

import java.time.Duration; //導入方法依賴的package包/類
private void updateUnitsToPrint() {
    LocalDate mStartDate = getStartDate();
    LocalDate mEndDate = getEndDate();

    if (mStartDate == null || mEndDate == null) {
        return;
    }

    Duration duration = Duration.between(mStartDate.atTime(LocalTime.MIN), mEndDate.atStartOfDay().plusDays(1));
    long days = duration.toDays();

    if (days > 0) {
        switch (getViewType()) {
            case DAY_VIEW:
                setUnitsToPrint((int) days);
                break;

            case WEEK_VIEW:
                setUnitsToPrint((int) (days / 7));
                break;

            case MONTH_VIEW:
                setUnitsToPrint((int) days / 30);
                break;

            default:
                throw new UnsupportedOperationException("Not supported yet!: " + getViewType());
        }
    } else {
        setUnitsToPrint(0);
    }
}
 
開發者ID:dlemmermann,項目名稱:CalendarFX,代碼行數:33,代碼來源:TimeRangeView.java

示例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)"));
    });
}
 
開發者ID:killjoy1221,項目名稱:WhoIs,代碼行數:38,代碼來源:Whois.java

示例8: addDays

import java.time.Duration; //導入方法依賴的package包/類
private static void addDays(Duration duration, StringBuilder timeString) {
    if (duration.toDays() >= 1) {
        timeString.append(duration.toDays());
        timeString.append(" days ");
    }
}
 
開發者ID:ciphertechsolutions,項目名稱:IO,代碼行數:7,代碼來源:Utils.java

示例9: daysRoundingUp

import java.time.Duration; //導入方法依賴的package包/類
public static long daysRoundingUp(Duration duration) {
    final long days = duration.toDays();
    return duration.equals(Duration.ofDays(days)) ? days : days + 1;
}
 
開發者ID:OvercastNetwork,項目名稱:ProjectAres,代碼行數:5,代碼來源:TimeUtils.java

示例10: getCostFailDay

import java.time.Duration; //導入方法依賴的package包/類
public int getCostFailDay()
{
	final Duration failDay = Duration.between(Instant.ofEpochMilli(getPaidUntil()), Instant.now());
	return failDay.isNegative() ? 0 : (int) failDay.toDays();
}
 
開發者ID:rubenswagner,項目名稱:L2J-Global,代碼行數:6,代碼來源:ClanHall.java

示例11: calculateSwapRate

import java.time.Duration; //導入方法依賴的package包/類
@VisibleForTesting
BigDecimal calculateSwapRate(Context context, Request request, BigDecimal dailyRate) {

    if (dailyRate == null) {
        return ZERO;
    }

    Instant now = request.getCurrentTime();

    if (now == null) {
        return ZERO;
    }

    ZonedDateTime expiry = context.getExpiry(Key.from(request));

    if (expiry == null) {
        return ZERO; // Not an expiry product.
    }

    ZonedDateTime sod = expiry.truncatedTo(ChronoUnit.DAYS);

    Duration swapFree = Duration.between(sod, expiry);

    Duration maturity = Duration.between(request.getCurrentTime(), expiry);

    if (maturity.compareTo(swapFree) < 0) {
        return ZERO; // Expiring without swap.
    }

    long swaps = maturity.toDays();

    double rate = Math.pow(ONE.add(dailyRate).doubleValue(), swaps) - 1;

    return BigDecimal.valueOf(rate).setScale(SCALE, UP);

}
 
開發者ID:after-the-sunrise,項目名稱:cryptotrader,代碼行數:37,代碼來源:BitflyerAdviser.java

示例12: 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

示例13: ZetDuur_id3CWQViUPQ1p

import java.time.Duration; //導入方法依賴的package包/類
static void ZetDuur_id3CWQViUPQ1p(@NotNull SNode __thisNode__, Duration duration) {
  Long duur = duration.toDays();
  duur = duur / 365;
  SPropertyOperations.set(__thisNode__, MetaAdapterFactory.getProperty(0x61be2dc6a1404defL, 0xa5927499aa2bac19L, 0x46db587183b322e6L, 0x46db587183b322eaL, "jaren"), duur.toString());
}
 
開發者ID:diederikd,項目名稱:DeBrug,代碼行數:6,代碼來源:Jaren__BehaviorDescriptor.java

示例14: ZetDuur_id3CWQViUPQ1p

import java.time.Duration; //導入方法依賴的package包/類
static void ZetDuur_id3CWQViUPQ1p(@NotNull SNode __thisNode__, Duration duration) {
  Long duur = duration.toDays();
  SPropertyOperations.set(__thisNode__, MetaAdapterFactory.getProperty(0x61be2dc6a1404defL, 0xa5927499aa2bac19L, 0x46db587183b2cda8L, 0x46db587183b2cda9L, "dagen"), duur.toString());
}
 
開發者ID:diederikd,項目名稱:DeBrug,代碼行數:5,代碼來源:Dagen__BehaviorDescriptor.java

示例15: ZetDuur_id3CWQViUPQ1p

import java.time.Duration; //導入方法依賴的package包/類
static void ZetDuur_id3CWQViUPQ1p(@NotNull SNode __thisNode__, Duration duration) {
  Long duur = duration.toDays();
  duur = duur / 30;
  SPropertyOperations.set(__thisNode__, MetaAdapterFactory.getProperty(0x61be2dc6a1404defL, 0xa5927499aa2bac19L, 0x46db587183b2cdcbL, 0x46db587183b2cdccL, "maanden"), duur.toString());
}
 
開發者ID:diederikd,項目名稱:DeBrug,代碼行數:6,代碼來源:Maanden__BehaviorDescriptor.java


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