當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。