当前位置: 首页>>代码示例>>Java>>正文


Java ZonedDateTime.truncatedTo方法代码示例

本文整理汇总了Java中java.time.ZonedDateTime.truncatedTo方法的典型用法代码示例。如果您正苦于以下问题:Java ZonedDateTime.truncatedTo方法的具体用法?Java ZonedDateTime.truncatedTo怎么用?Java ZonedDateTime.truncatedTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.time.ZonedDateTime的用法示例。


在下文中一共展示了ZonedDateTime.truncatedTo方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: toIntervalStart

import java.time.ZonedDateTime; //导入方法依赖的package包/类
public ZonedDateTime toIntervalStart(ZonedDateTime time) {
    ZonedDateTime start;
    switch (ChronoUnit.valueOf(unit.toString().toUpperCase())) {
        case SECONDS:
            start = time.truncatedTo(ChronoUnit.MINUTES);
            break;
        case MINUTES:
            start = time.truncatedTo(ChronoUnit.HOURS);
            break;
        case HOURS:
            start = time.truncatedTo(ChronoUnit.DAYS);
            break;
        case DAYS:
            start = time.with(TemporalAdjusters.firstDayOfYear()).truncatedTo(ChronoUnit.DAYS);
            break;
        default:
            start = time.with(TemporalAdjusters.firstDayOfYear()).truncatedTo(ChronoUnit.DAYS);
    }
    long haveMillis = Duration.between(start, time).toMillis();
    long maxMillis = duration.toMillis();
    long periods = haveMillis / maxMillis;
    start = start.plus(duration.multipliedBy(periods));
    return start;
}
 
开发者ID:hylkevds,项目名称:SensorThingsProcessor,代码行数:25,代码来源:ProcessorBatchAggregate.java

示例2: truncate

import java.time.ZonedDateTime; //导入方法依赖的package包/类
public static ZonedDateTime truncate(ZonedDateTime time, ChronoUnit unit) {
    switch (unit) {
        case NANOS:
        case MICROS:
        case MILLIS:
        case SECONDS:
        case MINUTES:
        case HOURS:
        case HALF_DAYS:
        case DAYS:
            return time.truncatedTo(unit);
        case MONTHS:
            return time.truncatedTo(DAYS).withDayOfMonth(1);
        case YEARS:
            return time.truncatedTo(DAYS).withDayOfYear(1);
        default:
            throw new UnsupportedTemporalTypeException("Invalid unit for truncation: " + unit);
    }
}
 
开发者ID:StefaniniInspiring,项目名称:pugtsdb,代码行数:20,代码来源:Temporals.java

示例3: truncate

import java.time.ZonedDateTime; //导入方法依赖的package包/类
public static ZonedDateTime truncate(ZonedDateTime time, ChronoUnit unit,
                                     int stepRate, DayOfWeek firstDayOfWeek) {
    switch (unit) {
        case DAYS:
            return adjustField(time, DAY_OF_YEAR, stepRate).truncatedTo(unit);
        case HALF_DAYS:
            return time.truncatedTo(unit);
        case HOURS:
            return adjustField(time, HOUR_OF_DAY, stepRate).truncatedTo(unit);
        case MINUTES:
            return adjustField(time, MINUTE_OF_HOUR, stepRate)
                    .truncatedTo(unit);
        case SECONDS:
            return adjustField(time, SECOND_OF_MINUTE, stepRate).truncatedTo(
                    unit);
        case MILLIS:
            return adjustField(time, MILLI_OF_SECOND, stepRate).truncatedTo(
                    unit);
        case MICROS:
            return adjustField(time, MICRO_OF_SECOND, stepRate).truncatedTo(
                    unit);
        case NANOS:
            return adjustField(time, NANO_OF_SECOND, stepRate)
                    .truncatedTo(unit);
        case MONTHS:
            return time
                    .with(MONTH_OF_YEAR,
                            Math.max(
                                    1,
                                    time.get(MONTH_OF_YEAR)
                                            - time.get(MONTH_OF_YEAR)
                                            % stepRate)).withDayOfMonth(1)
                    .truncatedTo(DAYS);
        case YEARS:
            return adjustField(time, ChronoField.YEAR, stepRate).withDayOfYear(
                    1).truncatedTo(DAYS);
        case WEEKS:
            return time.with(DAY_OF_WEEK, firstDayOfWeek.getValue()).truncatedTo(
                    DAYS);
        case DECADES:
            int decade = time.getYear() / 10 * 10;
            return time.with(ChronoField.YEAR, decade).withDayOfYear(1)
                    .truncatedTo(DAYS);
        case CENTURIES:
            int century = time.getYear() / 100 * 100;
            return time.with(ChronoField.YEAR, century).withDayOfYear(1)
                    .truncatedTo(DAYS);
        case MILLENNIA:
            int millenium = time.getYear() / 1000 * 1000;
            return time.with(ChronoField.YEAR, millenium).withDayOfYear(1)
                    .truncatedTo(DAYS);
        default:
    }

    return time;
}
 
开发者ID:dlemmermann,项目名称:CalendarFX,代码行数:57,代码来源:Util.java

示例4: calculateSwapRate

import java.time.ZonedDateTime; //导入方法依赖的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

示例5: parseConstants

import java.time.ZonedDateTime; //导入方法依赖的package包/类
private static void parseConstants(final char[] chars, final Part[] parts, final long nowEpochMilli) {
    final ZonedDateTime now = ZonedDateTime.ofInstant(Instant.ofEpochMilli(nowEpochMilli), ZoneOffset.UTC);
    final String expression = new String(chars);
    for (final DatePoint datePoint : DatePoint.values()) {
        final String function = datePoint.getFunction();

        int start = expression.indexOf(function, 0);
        while (start != -1) {
            final int end = start + function.length();

            // Obliterate the matched part of the expression so it can't be matched by any other matcher.
            Arrays.fill(chars, start, end, ' ');

            ZonedDateTime time = null;
            switch (datePoint) {
                case NOW:
                    time = now;
                    break;
                case SECOND:
                    time = now.truncatedTo(ChronoUnit.SECONDS);
                    break;
                case MINUTE:
                    time = now.truncatedTo(ChronoUnit.MINUTES);
                    break;
                case HOUR:
                    time = now.truncatedTo(ChronoUnit.HOURS);
                    break;
                case DAY:
                    time = now.truncatedTo(ChronoUnit.DAYS);
                    break;
                case WEEK:
                    TemporalField fieldISO = WeekFields.of(Locale.UK).dayOfWeek();
                    time = now.with(fieldISO, 1); // Monday
                    time = time.truncatedTo(ChronoUnit.DAYS);
                    break;
                case MONTH:
                    time = ZonedDateTime.of(now.getYear(), now.getMonthValue(), 1, 0, 0, 0, 0, now.getZone());
                    break;
                case YEAR:
                    time = ZonedDateTime.of(now.getYear(), 1, 1, 0, 0, 0, 0, now.getZone());
                    break;
            }

            parts[start] = new Part(function, time);

            start = expression.indexOf(function, end);
        }
    }
}
 
开发者ID:gchq,项目名称:stroom-query,代码行数:50,代码来源:DateExpressionParser.java


注:本文中的java.time.ZonedDateTime.truncatedTo方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。