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


Java LocalDateTime.withSecond方法代码示例

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


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

示例1: test_withSecond_normal

import java.time.LocalDateTime; //导入方法依赖的package包/类
@Test
public void test_withSecond_normal() {
    LocalDateTime t = TEST_2007_07_15_12_30_40_987654321;
    for (int i = 0; i < 60; i++) {
        t = t.withSecond(i);
        assertEquals(t.getSecond(), i);
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:9,代码来源:TCKLocalDateTime.java

示例2: makeDatesEven

import java.time.LocalDateTime; //导入方法依赖的package包/类
private List<LocalDateTime> makeDatesEven(List<LocalDateTime> dates, LocalDateTime dateTime) {
    // If the dates contain more dates than just the lower and upper bounds, make the dates in between even.
    if (dates.size() > 2) {
        List<LocalDateTime> evenDates = new ArrayList<>();

        // For each interval, modify the date slightly by a few millis, to make sure they are different days.
        // This is because Axis stores each value and won't update the tick labels, if the value is already known.
        // This happens if you display days and then add a date many years in the future the tick label will still be displayed as day.
        for (int i = 0; i < dates.size(); i++) {
            dateTime = dates.get(i);
            switch (currentInterval.getInterval()) {
                case YEARS:
                    // If its not the first or last date (lower and upper bound), make the year begin with first month and let the months begin with first day.
                    if (i != 0 && i != dates.size() - 1) {
                        dateTime.withMonth(1);
                        dateTime.withDayOfMonth(1);
                    }
                    dateTime.withHour(0);
                    dateTime.withMinute(0);
                    dateTime.withSecond(0);
                    dateTime.withNano(6000000);
                    break;
                case MONTHS:
                    // If its not the first or last date (lower and upper bound), make the months begin with first day.
                    if (i != 0 && i != dates.size() - 1) {
                        dateTime.withDayOfMonth(1);
                    }
                    dateTime.withHour(0);
                    dateTime.withMinute(0);
                    dateTime.withSecond(0);
                    dateTime.withNano(5000000);
                    break;
                case WEEKS:
                    // Make weeks begin with first day of week?
                    dateTime.withHour(0);
                    dateTime.withMinute(0);
                    dateTime.withSecond(0);
                    dateTime.withNano(4000000);
                    break;
                case DAYS:
                    dateTime.withHour(0);
                    dateTime.withMinute(0);
                    dateTime.withSecond(0);
                    dateTime.withNano(3000000);
                    break;
                case HOURS:
                    if (i != 0 && i != dates.size() - 1) {
                        dateTime.withMinute(0);
                        dateTime.withSecond(0);
                    }
                    dateTime.withNano(2000000);
                    break;
                case MINUTES:
                    if (i != 0 && i != dates.size() - 1) {
                        dateTime.withSecond(0);
                    }
                    dateTime.withNano(1000000);
                    break;
                case SECONDS:
                    dateTime.withSecond(0);
                    break;

            }
            evenDates.add(dateTime);
        }

        return evenDates;
    } else {
        return dates;
    }
}
 
开发者ID:HanSolo,项目名称:charts,代码行数:72,代码来源:Axis.java


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