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


Java LocalDateTime.toEpochSecond方法代码示例

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


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

示例1: getFollowing

import java.time.LocalDateTime; //导入方法依赖的package包/类
@GET
@Path("/{username}/following")
public Response getFollowing(@PathParam("username") final String username,
                             @QueryParam("limit") @DefaultValue("25") final Integer limit,
                             @QueryParam("since") final Long since,
                             @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 = findUser(username, db);
        for (Relationship r1: user.getRelationships(Direction.OUTGOING, RelationshipTypes.FOLLOWS)) {
            Long time = (Long)r1.getProperty(TIME);
            if(time < latest) {
                Node following = r1.getEndNode();
                Map<String, Object> result = getUserAttributes(following);
                result.put(TIME, time);
                results.add(result);
            }
        }
        tx.success();
    }
    results.sort(Comparator.comparing(m -> (Long) m.get(TIME), reverseOrder()));

    return Response.ok().entity(objectMapper.writeValueAsString(
            results.subList(0, Math.min(results.size(), limit))))
            .build();
}
 
开发者ID:maxdemarzi,项目名称:grittier_ext,代码行数:36,代码来源:Users.java

示例2: getLatestTime

import java.time.LocalDateTime; //导入方法依赖的package包/类
public static Long getLatestTime(@QueryParam("since") Long since) {
    LocalDateTime dateTime;
    if (since == null) {
        dateTime = LocalDateTime.now(utc);
    } else {
        dateTime = LocalDateTime.ofEpochSecond(since, 0, ZoneOffset.UTC);
    }
    return dateTime.toEpochSecond(ZoneOffset.UTC);
}
 
开发者ID:maxdemarzi,项目名称:grittier_ext,代码行数:10,代码来源:Time.java

示例3: getFollowers

import java.time.LocalDateTime; //导入方法依赖的package包/类
@GET
@Path("/{username}/followers")
public Response getFollowers(@PathParam("username") final String username,
                             @QueryParam("limit") @DefaultValue("25") final Integer limit,
                             @QueryParam("since") final Long since,
                             @Context GraphDatabaseService db) throws IOException {
    ArrayList<Map<String, Object>> results = new ArrayList<>();
    // TODO: 4/3/17 Add Recent Array for Users with > 100k Followers
    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 = findUser(username, db);
        for (Relationship r1: user.getRelationships(Direction.INCOMING, RelationshipTypes.FOLLOWS)) {
            Long time = (Long)r1.getProperty(TIME);
            if(time < latest) {
                Node follower = r1.getStartNode();
                Map<String, Object> result = getUserAttributes(follower);
                result.put(TIME, time);
                results.add(result);
            }
        }
        tx.success();
    }
    results.sort(Comparator.comparing(m -> (Long) m.get(TIME), reverseOrder()));

    return Response.ok().entity(objectMapper.writeValueAsString(
            results.subList(0, Math.min(results.size(), limit))))
            .build();
}
 
开发者ID:maxdemarzi,项目名称:grittier_ext,代码行数:36,代码来源:Users.java

示例4: Time

import java.time.LocalDateTime; //导入方法依赖的package包/类
public Time(LocalDateTime time) {
	this(time.toEpochSecond(zoneOffset));
}
 
开发者ID:mobitopp,项目名称:connection-scan,代码行数:4,代码来源:Time.java

示例5: getLocationOfDate

import java.time.LocalDateTime; //导入方法依赖的package包/类
public double getLocationOfDate(LocalDateTime date) {
    return ((date.toEpochSecond(ZoneOffset.UTC) - currDay.toEpochSecond(ZoneOffset.UTC)) / 60)
            * getWidthPerMinute() + TwoDayViewPresenter.SPOT_NAME_WIDTH;

}
 
开发者ID:kiegroup,项目名称:optashift-employee-rostering,代码行数:6,代码来源:TwoDayViewState.java

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

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

示例8: Ldt2Long

import java.time.LocalDateTime; //导入方法依赖的package包/类
public final static long Ldt2Long(final LocalDateTime ldt) {
	return ldt.toEpochSecond(ZoneOffset.UTC);
}
 
开发者ID:zc8424,项目名称:QuantTester,代码行数:4,代码来源:DateTimeHelper.java

示例9: Axis

import java.time.LocalDateTime; //导入方法依赖的package包/类
public Axis(final LocalDateTime START, final LocalDateTime END, final Orientation ORIENTATION, final Position POSITION) {
    if (VERTICAL == ORIENTATION) {
        if (Position.LEFT != POSITION && Position.RIGHT != POSITION && Position.CENTER != POSITION) {
            throw new IllegalArgumentException("Wrong combination of orientation and position!");
        }
    } else {
        if (Position.TOP != POSITION && Position.BOTTOM != POSITION && Position.CENTER != POSITION) {
            throw new IllegalArgumentException("Wrong combination of orientation and position!");
        }
    }

    getStylesheets().add(Axis.class.getResource("chart.css").toExternalForm());
    _minValue                         = START.toEpochSecond(Helper.getZoneOffset());
    _start                            = START;
    _maxValue                         = END.toEpochSecond(Helper.getZoneOffset());
    _end                              = END;

    _type                             = AxisType.DATE;
    _autoScale                        = true;
    _title                            = "";
    _unit                             = "";
    _orientation                      = ORIENTATION;
    _position                         = POSITION;
    _axisBackgroundColor              = Color.TRANSPARENT;
    _axisColor                        = Color.BLACK;
    _tickLabelColor                   = Color.BLACK;
    _minorTickMarkColor               = Color.BLACK;
    _mediumTickMarkColor              = Color.BLACK;
    _majorTickMarkColor               = Color.BLACK;
    _zeroColor                        = Color.BLACK;
    _zeroPosition                     = 0;
    _minorTickSpace                   = 1;
    _majorTickSpace                   = 10;
    _majorTickMarksVisible            = true;
    _mediumTickMarksVisible           = true;
    _minorTickMarksVisible            = true;
    _tickLabelsVisible                = true;
    _onlyFirstAndLastTickLabelVisible = false;
    _locale                           = Locale.US;
    _decimals                         = 0;
    _tickLabelOrientation             = TickLabelOrientation.HORIZONTAL;
    _tickLabelFormat                  = TickLabelFormat.NUMBER;
    _autoFontSize                     = true;
    _tickLabelFontSize                = 10;
    _titleFontSize                    = 10;
    _zoneId                           = ZoneId.systemDefault();
    _dateTimeFormatPattern            = "dd.MM.YY HH:mm:ss";
    currentInterval                   = Interval.SECOND_1;
    dateTimeFormatter                 = DateTimeFormatter.ofPattern(_dateTimeFormatPattern, _locale);
    tickLabelFormatString             = new StringBuilder("%.").append(Integer.toString(_decimals)).append("f").toString();

    initGraphics();
    registerListeners();
}
 
开发者ID:HanSolo,项目名称:charts,代码行数:55,代码来源:Axis.java

示例10: createTickValues

import java.time.LocalDateTime; //导入方法依赖的package包/类
private List<LocalDateTime> createTickValues(final double WIDTH, final LocalDateTime START, final LocalDateTime END) {
    List<LocalDateTime> dateList = new ArrayList<>();
    LocalDateTime       dateTime = LocalDateTime.now();

    if (null == START || null == END) return dateList;

    // The preferred gap which should be between two tick marks.
    double majorTickSpace = 100;
    double noOfTicks      = WIDTH / majorTickSpace;

    List<LocalDateTime> previousDateList = new ArrayList<>();
    Interval            previousInterval = Interval.values()[0];

    // Starting with the greatest interval, add one of each dateTime unit.
    for (Interval interval : Interval.values()) {
        // Reset the dateTime.
        dateTime = LocalDateTime.of(START.toLocalDate(), START.toLocalTime());
        // Clear the list.
        dateList.clear();
        previousDateList.clear();
        currentInterval = interval;

        // Loop as long we exceeded the END bound.
        while(dateTime.isBefore(END)) {
            dateList.add(dateTime);
            dateTime = dateTime.plus(interval.getAmount(), interval.getInterval());
        }

        // Then check the size of the list. If it is greater than the amount of ticks, take that list.
        if (dateList.size() > noOfTicks) {
            dateTime = LocalDateTime.of(START.toLocalDate(), START.toLocalTime());
            // Recheck if the previous interval is better suited.
            while(dateTime.isBefore(END) || dateTime.isEqual(END)) {
                previousDateList.add(dateTime);
                dateTime = dateTime.plus(previousInterval.getAmount(), previousInterval.getInterval());
            }
            break;
        }

        previousInterval = interval;
    }
    if (previousDateList.size() - noOfTicks > noOfTicks - dateList.size()) {
        dateList = previousDateList;
        currentInterval = previousInterval;
    }

    // At last add the END bound.
    dateList.add(END);

    List<LocalDateTime> evenDateList = makeDatesEven(dateList, dateTime);
    // If there are at least three dates, check if the gap between the START date and the second date is at least half the gap of the second and third date.
    // Do the same for the END bound.
    // If gaps between dates are to small, remove one of them.
    // This can occur, e.g. if the START bound is 25.12.2013 and years are shown. Then the next year shown would be 2014 (01.01.2014) which would be too narrow to 25.12.2013.
    if (evenDateList.size() > 2) {
        LocalDateTime secondDate       = evenDateList.get(1);
        LocalDateTime thirdDate        = evenDateList.get(2);
        LocalDateTime lastDate         = evenDateList.get(dateList.size() - 2);
        LocalDateTime previousLastDate = evenDateList.get(dateList.size() - 3);

        // If the second date is too near by the START bound, remove it.
        if (secondDate.toEpochSecond(ZoneOffset.ofHours(0)) - START.toEpochSecond(ZoneOffset.ofHours(0)) < thirdDate.toEpochSecond(ZoneOffset.ofHours(0)) - secondDate.toEpochSecond(ZoneOffset.ofHours(0))) {
            evenDateList.remove(secondDate);
        }

        // If difference from the END bound to the last date is less than the half of the difference of the previous two dates,
        // we better remove the last date, as it comes to close to the END bound.
        if (END.toEpochSecond(ZoneOffset.ofHours(0)) - lastDate.toEpochSecond(ZoneOffset.ofHours(0)) < ((lastDate.toEpochSecond(ZoneOffset.ofHours(0)) - previousLastDate.toEpochSecond(ZoneOffset.ofHours(0)) * 0.5))) {
            evenDateList.remove(lastDate);
        }
    }
    return evenDateList;
}
 
开发者ID:HanSolo,项目名称:charts,代码行数:74,代码来源:Axis.java

示例11: TYChartItem

import java.time.LocalDateTime; //导入方法依赖的package包/类
public TYChartItem(final LocalDateTime T, final double Y, final String NAME, final Color FILL, final Symbol SYMBOL) {
    super(T.toEpochSecond(Helper.getZoneOffset()), Y, NAME, FILL, Color.TRANSPARENT, SYMBOL);
    _t = T;
}
 
开发者ID:HanSolo,项目名称:charts,代码行数:5,代码来源:TYChartItem.java

示例12: toSeconds

import java.time.LocalDateTime; //导入方法依赖的package包/类
public static final long toSeconds(final LocalDateTime DATE_TIME, final ZoneOffset ZONE_OFFSET) { return DATE_TIME.toEpochSecond(ZONE_OFFSET); } 
开发者ID:HanSolo,项目名称:charts,代码行数:2,代码来源:Helper.java


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