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


Java LocalDateTime.minusSeconds方法代码示例

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


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

示例1: main

import java.time.LocalDateTime; //导入方法依赖的package包/类
public static void main(String[] args) {
    /*LocalDate date = LocalDate.of(2014, Month.JANUARY, 20);
    System.out.println(date);
    date = date.plusDays(2);
    System.out.println(date);
    date = date.plusWeeks(1);
    System.out.println(date);
    date = date.plusMonths(1);
    System.out.println(date);
    date = date.plusYears(5);
    System.out.println(date);*/

    LocalDate date = LocalDate.of(2020, Month.JANUARY, 20);
    LocalTime time = LocalTime.of(5, 15);
    LocalDateTime dateTime = LocalDateTime.of(date, time);
    System.out.println(dateTime);
    dateTime = dateTime.minusDays(1);
    System.out.println(dateTime);
    dateTime = dateTime.minusHours(10);
    System.out.println(dateTime);
    dateTime = dateTime.minusSeconds(30);
    System.out.println(dateTime);
}
 
开发者ID:huby,项目名称:java-se8-oca-study-guide,代码行数:24,代码来源:ManipulatingDatesAndTimes.java

示例2: test_toEpochSecond_beforeEpoch

import java.time.LocalDateTime; //导入方法依赖的package包/类
@Test
public void test_toEpochSecond_beforeEpoch() {
    LocalDateTime ldt = LocalDateTime.of(1970, 1, 1, 0, 0).plusHours(1);
    for (int i = 0; i < 100000; i++) {
        ZonedDateTime a = ZonedDateTime.of(ldt, ZONE_PARIS);
        assertEquals(a.toEpochSecond(), -i);
        ldt = ldt.minusSeconds(1);
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:10,代码来源:TCKZonedDateTime.java

示例3: test_minusSeconds_one

import java.time.LocalDateTime; //导入方法依赖的package包/类
@Test
public void test_minusSeconds_one() {
    LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT);
    LocalDate d = t.toLocalDate().minusDays(1);

    int hour = 0;
    int min = 0;
    int sec = 0;

    for (int i = 0; i < 3700; i++) {
        t = t.minusSeconds(1);
        sec--;
        if (sec == -1) {
            min--;
            sec = 59;

            if (min == -1) {
                hour--;
                min = 59;

                if (hour == -1) {
                    hour = 23;
                }
            }
        }

        assertEquals(t.toLocalDate(), d);
        assertEquals(t.getHour(), hour);
        assertEquals(t.getMinute(), min);
        assertEquals(t.getSecond(), sec);
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:33,代码来源:TCKLocalDateTime.java

示例4: test_minusSeconds_fromZero

import java.time.LocalDateTime; //导入方法依赖的package包/类
@Test(dataProvider="minusSeconds_fromZero")
public void test_minusSeconds_fromZero(int seconds, LocalDate date, int hour, int min, int sec) {
    LocalDateTime base = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT);
    LocalDateTime t = base.minusSeconds(seconds);

    assertEquals(date, t.toLocalDate());
    assertEquals(hour, t.getHour());
    assertEquals(min, t.getMinute());
    assertEquals(sec, t.getSecond());
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:11,代码来源:TCKLocalDateTime.java

示例5: testClac

import java.time.LocalDateTime; //导入方法依赖的package包/类
/**
 * 时间计算,减法操作
 */
@Test
public void testClac(){
    LocalDateTime ldt = LocalDateTime.now();

    System.out.println(ldt);

    // 减: 天
    LocalDateTime days = ldt.minusDays(1);
    System.out.println("day: " + days);

    // 减: 小时
    LocalDateTime hours = ldt.minusHours(1);
    System.out.println("hours: " + hours);

    // 减: 分钟
    LocalDateTime minutes = ldt.minusMinutes(1);
    System.out.println("minutes: " + minutes);

    // 减: 月
    LocalDateTime months = ldt.minusMonths(1);
    System.out.println("months: " + months);

    // 减: 纳秒
    LocalDateTime nanos = ldt.minusNanos(1);
    System.out.println("nanos: " + nanos);

    // 减: 秒
    LocalDateTime seconds = ldt.minusSeconds(1);
    System.out.println("seconds: " + seconds);

    // 减: 周
    LocalDateTime weeks = ldt.minusWeeks(1);
    System.out.println("weeks: " + weeks);

    // 减: 年
    LocalDateTime years = ldt.minusYears(1);
    System.out.println("years: " + years);

    System.out.println(ldt);
}
 
开发者ID:cbooy,项目名称:cakes,代码行数:44,代码来源:LocalDateTimeDemo.java


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