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


Java LocalDateTime.minusDays方法代码示例

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


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

示例1: returnedTimeSpanIsCorrect

import java.time.LocalDateTime; //导入方法依赖的package包/类
@Test
public void returnedTimeSpanIsCorrect() {
    final LocalDateTime toDateTime = LocalDateTime.of(2017, Month.APRIL, 8, 12, 30);
    final LocalDateTime fromDateTime = toDateTime.minusDays(historyOrderInDays);
    final long to = DateTimeUtil.millisFromDateTime(toDateTime);
    final long from = DateTimeUtil.millisFromDateTime(fromDateTime);
    stubServerTime().thenReturn(Single.just(to));

    final TimeSpan timeSpan = (TimeSpan) subscribe()
        .getEvents()
        .get(0)
        .get(0);

    assertThat(timeSpan.from(), equalTo(from));
    assertThat(timeSpan.to(), equalTo(to));
}
 
开发者ID:juxeii,项目名称:dztools,代码行数:17,代码来源:HistoryOrdersDatesTest.java

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

示例3: testLocalDateTime

import java.time.LocalDateTime; //导入方法依赖的package包/类
public static void testLocalDateTime() {
        //使用默认时区时钟瞬时时间创建 Clock.systemDefaultZone() -->即相对于 ZoneId.systemDefault()默认时区  
        LocalDateTime now = LocalDateTime.now();
        System.out.println(now);
//自定义时区  
        LocalDateTime now2 = LocalDateTime.now(ZoneId.of("Europe/Paris"));
        System.out.println(now2);//会以相应的时区显示日期  
//自定义时钟  
        Clock clock = Clock.system(ZoneId.of("Asia/Dhaka"));
        LocalDateTime now3 = LocalDateTime.now(clock);
        System.out.println(now3);//会以相应的时区显示日期  
//不需要写什么相对时间 如java.util.Date 年是相对于1900 月是从0开始  
//2013-12-31 23:59  
        LocalDateTime d1 = LocalDateTime.of(2013, 12, 31, 23, 59);
//年月日 时分秒 纳秒  
        LocalDateTime d2 = LocalDateTime.of(2013, 12, 31, 23, 59, 59, 11);
//使用瞬时时间 + 时区  
        Instant instant = Instant.now();
        LocalDateTime d3 = LocalDateTime.ofInstant(Instant.now(), ZoneId.systemDefault());
        System.out.println(d3);
//解析String--->LocalDateTime  
        LocalDateTime d4 = LocalDateTime.parse("2013-12-31T23:59");
        System.out.println(d4);
        LocalDateTime d5 = LocalDateTime.parse("2013-12-31T23:59:59.999");//999毫秒 等价于999000000纳秒  
        System.out.println(d5);
//使用DateTimeFormatter API 解析 和 格式化  
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm:ss");
        LocalDateTime d6 = LocalDateTime.parse("2013/12/31 23:59:59", formatter);
        System.out.println(formatter.format(d6));
//时间获取  
        System.out.println(d6.getYear());
        System.out.println(d6.getMonth());
        System.out.println(d6.getDayOfYear());
        System.out.println(d6.getDayOfMonth());
        System.out.println(d6.getDayOfWeek());
        System.out.println(d6.getHour());
        System.out.println(d6.getMinute());
        System.out.println(d6.getSecond());
        System.out.println(d6.getNano());
//时间增减  
        LocalDateTime d7 = d6.minusDays(1);
        LocalDateTime d8 = d7.plus(1, IsoFields.QUARTER_YEARS);
//LocalDate 即年月日 无时分秒  
//LocalTime即时分秒 无年月日  
//API和LocalDateTime类似就不演示了  
    }
 
开发者ID:juebanlin,项目名称:util4j,代码行数:47,代码来源:TimeIntroduction.java

示例4: getPosts

import java.time.LocalDateTime; //导入方法依赖的package包/类
@GET
public Response getPosts(@PathParam("username") final String username,
                         @QueryParam("limit") @DefaultValue("25") final Integer limit,
                         @QueryParam("since") final Long since,
                         @QueryParam("username2") final String username2,
                         @Context GraphDatabaseService db) throws IOException {
    ArrayList<Map<String, Object>> results = new ArrayList<>();
    LocalDateTime dateTime;
    if (since == null) {
        dateTime = LocalDateTime.now(utc);
    } else {
        dateTime = LocalDateTime.ofEpochSecond(since, 0, ZoneOffset.UTC);
    }
    Long latest = dateTime.toEpochSecond(ZoneOffset.UTC);

    try (Transaction tx = db.beginTx()) {
        Node user = Users.findUser(username, db);
        Node user2 = null;
        if (username2 != null) {
            user2 = Users.findUser(username2, db);
        }

        Map userProperties = user.getAllProperties();
        LocalDateTime earliest = LocalDateTime.ofEpochSecond((Long)userProperties.get(TIME), 0, ZoneOffset.UTC);
        int count = 0;
        while (count < limit && (dateTime.isAfter(earliest))) {
            RelationshipType relType = RelationshipType.withName("POSTED_ON_" +
                    dateTime.format(dateFormatter));

            for (Relationship r1 : user.getRelationships(Direction.OUTGOING, relType)) {
                Node post = r1.getEndNode();
                Map<String, Object> result = post.getAllProperties();
                Long time = (Long)r1.getProperty("time");
                if(time < latest) {
                    result.put(TIME, time);
                    result.put(USERNAME, username);
                    result.put(NAME, userProperties.get(NAME));
                    result.put(HASH, userProperties.get(HASH));
                    result.put(LIKES, post.getDegree(RelationshipTypes.LIKES));
                    result.put(REPOSTS, post.getDegree(Direction.INCOMING)
                            - 1 // for the Posted Relationship Type
                            - post.getDegree(RelationshipTypes.LIKES)
                            - post.getDegree(RelationshipTypes.REPLIED_TO));
                    if (user2 != null) {
                        result.put(LIKED, userLikesPost(user2, post));
                        result.put(REPOSTED, userRepostedPost(user2, post));
                    }
                    results.add(result);
                    count++;
                }
            }
            dateTime = dateTime.minusDays(1);
        }
        tx.success();
    }

    results.sort(Comparator.comparing(m -> (Long) m.get(TIME), reverseOrder()));

    return Response.ok().entity(objectMapper.writeValueAsString(results)).build();
}
 
开发者ID:maxdemarzi,项目名称:grittier_ext,代码行数:61,代码来源:Posts.java

示例5: getTags

import java.time.LocalDateTime; //导入方法依赖的package包/类
@GET
@Path("/{hashtag}")
public Response getTags(@PathParam("hashtag") final String hashtag,
                         @QueryParam("limit") @DefaultValue("25") final Integer limit,
                         @QueryParam("since") final Long since,
                         @QueryParam("username") final String username,
                         @Context GraphDatabaseService db) throws IOException {
    ArrayList<Map<String, Object>> results = new ArrayList<>();
    LocalDateTime dateTime;
    if (since == null) {
        dateTime = LocalDateTime.now(utc);
    } else {
        dateTime = LocalDateTime.ofEpochSecond(since, 0, ZoneOffset.UTC);
    }
    Long latest = dateTime.toEpochSecond(ZoneOffset.UTC);

    try (Transaction tx = db.beginTx()) {
        Node user = null;
        if (username != null) {
            user = Users.findUser(username, db);
        }

        Node tag = db.findNode(Labels.Tag, NAME, hashtag.toLowerCase());
        if (tag != null) {
            LocalDateTime earliestTag = LocalDateTime.ofEpochSecond((Long) tag.getProperty(TIME), 0, ZoneOffset.UTC);

            int count = 0;
            while (count < limit && (dateTime.isAfter(earliestTag))) {
                RelationshipType relType = RelationshipType.withName("TAGGED_ON_" +
                        dateTime.format(dateFormatter));

                for (Relationship r1 : tag.getRelationships(Direction.INCOMING, relType)) {
                    Node post = r1.getStartNode();
                    Map<String, Object> result = post.getAllProperties();
                    Long time = (Long) result.get("time");

                    if (count < limit && time < latest) {
                        Node author = getAuthor(post, time);
                        Map userProperties = author.getAllProperties();
                        result.put(USERNAME, userProperties.get(USERNAME));
                        result.put(NAME, userProperties.get(NAME));
                        result.put(HASH, userProperties.get(HASH));
                        result.put(LIKES, post.getDegree(RelationshipTypes.LIKES));
                        result.put(REPOSTS, post.getDegree(Direction.INCOMING)
                                - 1 // for the Posted Relationship Type
                                - post.getDegree(RelationshipTypes.LIKES)
                                - post.getDegree(RelationshipTypes.REPLIED_TO));
                        if (user != null) {
                            result.put(LIKED, userLikesPost(user, post));
                            result.put(REPOSTED, userRepostedPost(user, post));
                        }
                        results.add(result);
                        count++;
                    }
                }
                dateTime = dateTime.minusDays(1);
            }
            tx.success();
            results.sort(Comparator.comparing(m -> (Long) m.get(TIME), reverseOrder()));
        } else {
            throw TagExceptions.tagNotFound;
        }
    }
    return Response.ok().entity(objectMapper.writeValueAsString(results)).build();
}
 
开发者ID:maxdemarzi,项目名称:grittier_ext,代码行数:66,代码来源:Tags.java

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