當前位置: 首頁>>代碼示例>>Java>>正文


Java LocalDateTime.ofEpochSecond方法代碼示例

本文整理匯總了Java中java.time.LocalDateTime.ofEpochSecond方法的典型用法代碼示例。如果您正苦於以下問題:Java LocalDateTime.ofEpochSecond方法的具體用法?Java LocalDateTime.ofEpochSecond怎麽用?Java LocalDateTime.ofEpochSecond使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.time.LocalDateTime的用法示例。


在下文中一共展示了LocalDateTime.ofEpochSecond方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: main

import java.time.LocalDateTime; //導入方法依賴的package包/類
/**
	 * 程序執行入口.
	 *
	 * @param args 命令行參數
	 */
	public static void main(String[] args) {

		LocalDateTime today = LocalDateTime.now(); // |\longremark{獲得當前的日期時間對象}|
		System.out.println("Current DateTime=" + today);

		//Current Date using LocalDate and LocalTime
		today = LocalDateTime.of(LocalDate.now(), LocalTime.now());// |\longremark{根據給定的LocalDate和LocalTime創建日期時間對象}|
		System.out.println("Current DateTime=" + today);

		LocalDateTime specificDate = LocalDateTime.of(2014, 1, 1, 10, 10, 30);// |\longremark{根據給定的日期和時間創建日期時間對象}|
		System.out.println("Specific Date=" + specificDate);

		LocalDateTime todayShanghai = LocalDateTime.now(ZoneId.of("Asia/Shanghai"));// |\longremark{根據給定的時區創建日期時間對象}|
		System.out.println("Current Date in CST=" + todayShanghai);

		LocalDateTime dateFromBase = LocalDateTime.ofEpochSecond(10000, 0, ZoneOffset.UTC);// |\longremark{從1970-1-1開始計算的日期時間對象}|
		System.out.println("10000th second time from 01/01/1970= " + dateFromBase);

//		LocalDateTime test1 = LocalDateTime.of(LocalDate.now(), null);
//		System.out.println("test1:" + test1);

	}
 
開發者ID:subaochen,項目名稱:java-tutorial,代碼行數:28,代碼來源:LocalDateTimeTest.java

示例2: getPost

import java.time.LocalDateTime; //導入方法依賴的package包/類
public static Node getPost(Node author, Long time) {
    LocalDateTime postedDateTime = LocalDateTime.ofEpochSecond(time, 0, ZoneOffset.UTC);
    RelationshipType original = RelationshipType.withName("POSTED_ON_" +
            postedDateTime.format(dateFormatter));
    Node post = null;
    for(Relationship r1 : author.getRelationships(Direction.OUTGOING, original)) {
        Node potential = r1.getEndNode();
        if (time.equals(potential.getProperty(TIME))) {
            post = potential;
            break;
        }
    }
    if(post == null) { throw PostExceptions.postNotFound; };

    return post;
}
 
開發者ID:maxdemarzi,項目名稱:grittier_ext,代碼行數:17,代碼來源:Users.java

示例3: testSetDateAt

import java.time.LocalDateTime; //導入方法依賴的package包/類
@Test
public void testSetDateAt() {
    // 1987-04-15
    long enc = 20 * 60;
    LocalDateTime date = LocalDateTime.of(1984, 1, 1, 0, 0).plusSeconds(enc * 86400);

    long S7_TIME_OFFSET = 441763200000L;
    long millis = enc * 86400000L + S7_TIME_OFFSET;
    Date date2 = new Date(millis);
    assertEquals(date.toInstant(ZoneOffset.UTC), date2.toInstant());

    LocalDateTime date3 = LocalDateTime.ofEpochSecond(millis / 1000, 0, ZoneOffset.UTC);
    assertEquals(date, date3);

    byte[] buffer = new byte[32];
    Arrays.fill(buffer, (byte) 0);
    LocalDateTime ldt = LocalDateTime.ofInstant(date.toInstant(ZoneOffset.UTC), ZoneOffset.systemDefault());
    S7.setDateTimeAt(buffer, 0, ldt);

    byte[] buffer1 = new byte[32];
    Arrays.fill(buffer1, (byte) 0);
    S7.setDateAt(buffer1, 0, date2);
    Assert.assertArrayEquals(buffer, buffer1);
}
 
開發者ID:comtel2000,項目名稱:mokka7,代碼行數:25,代碼來源:S7Test.java

示例4: ofInstant

import java.time.LocalDateTime; //導入方法依賴的package包/類
/**
 * Obtains an instance from an instant using the specified time-zone.
 *
 * @param chrono  the chronology, not null
 * @param instant  the instant, not null
 * @param zone  the zone identifier, not null
 * @return the zoned date-time, not null
 */
static ChronoZonedDateTimeImpl<?> ofInstant(Chronology chrono, Instant instant, ZoneId zone) {
    ZoneRules rules = zone.getRules();
    ZoneOffset offset = rules.getOffset(instant);
    Objects.requireNonNull(offset, "offset");  // protect against bad ZoneRules
    LocalDateTime ldt = LocalDateTime.ofEpochSecond(instant.getEpochSecond(), instant.getNano(), offset);
    ChronoLocalDateTimeImpl<?> cldt = (ChronoLocalDateTimeImpl<?>)chrono.localDateTime(ldt);
    return new ChronoZonedDateTimeImpl<>(cldt, offset, zone);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:17,代碼來源:ChronoZonedDateTimeImpl.java

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

示例6: getResults

import java.time.LocalDateTime; //導入方法依賴的package包/類
@Override
public Stream<TtResult> getResults(Long ttId, Long from, Long to, ChronoUnit unit) {
    LocalDateTime fromDate = LocalDateTime.ofEpochSecond(from, 0, ZoneOffset.UTC);
    LocalDateTime toDate = LocalDateTime.ofEpochSecond(to, 0, ZoneOffset.UTC);


    ViewResult results = bucket.query(
            ViewQuery.from(DEFAULT_DESIGN_DOCUMENT, TT_RESULTS_BY_DATE_VIEW)
                    .startKey(JsonArray.from(
                            ttId,
                            fromDate.get(ChronoField.YEAR),
                            fromDate.get(ChronoField.MONTH_OF_YEAR),
                            fromDate.get(ChronoField.DAY_OF_MONTH),
                            fromDate.get(ChronoField.HOUR_OF_DAY),
                            fromDate.get(ChronoField.MINUTE_OF_HOUR),
                            fromDate.get(ChronoField.SECOND_OF_MINUTE)
                    ))
                    .endKey(JsonArray.from(
                            ttId,
                            toDate.get(ChronoField.YEAR),
                            toDate.get(ChronoField.MONTH_OF_YEAR),
                            toDate.get(ChronoField.DAY_OF_MONTH),
                            toDate.get(ChronoField.HOUR_OF_DAY),
                            toDate.get(ChronoField.MINUTE_OF_HOUR),
                            toDate.get(ChronoField.SECOND_OF_MINUTE),
                            "\uEFFF"
                    ))
                    .groupLevel(1 + CouchbaseUtils.chronoUnitToGroupLevel(unit))
    );
    return StreamSupport.stream(results.spliterator(), false)
            .map(row -> row.value().toString())
            .map(json -> gson.fromJson(json, TtResult.class));
}
 
開發者ID:maxcleme,項目名稱:f4f-tts,代碼行數:34,代碼來源:CouchbaseTtsDao.java

示例7: TwoDayViewState

import java.time.LocalDateTime; //導入方法依賴的package包/類
public TwoDayViewState(TwoDayViewPresenter<G, I, D> presenter) {
    this.presenter = presenter;
    baseDate = LocalDateTime.ofEpochSecond(0, 0, ZoneOffset.UTC);
    currDay = baseDate;
    visibleDirty = true;
    allDirty = true;
    screenWidth = 1;
    screenHeight = 1;
    groupShifts = new HashMap<>();
    scrollBarPos = 0;
    scrollBarLength = 1;
    scrollBarHandleLength = 1;
    groupIndexOf = new HashMap<>();
}
 
開發者ID:kiegroup,項目名稱:optashift-employee-rostering,代碼行數:15,代碼來源:TwoDayViewState.java

示例8: asDateTime

import java.time.LocalDateTime; //導入方法依賴的package包/類
private static LocalDateTime asDateTime(Number value) {
	if (value != null) {
		if (TypeUtils.isIntegerNumber(value.getClass())) {
			return LocalDateTime.ofEpochSecond(value.longValue(), 0, ZoneOffset.UTC);
		}
	}
	return null;
}
 
開發者ID:holon-platform,項目名稱:holon-datastore-jdbc,代碼行數:9,代碼來源:SQLiteDialect.java

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

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

示例11: factory_ofEpochSecond_longOffset_afterEpoch

import java.time.LocalDateTime; //導入方法依賴的package包/類
@Test
public void factory_ofEpochSecond_longOffset_afterEpoch() {
    LocalDateTime base = LocalDateTime.of(1970, 1, 1, 2, 0, 0, 500);
    for (int i = 0; i < 100000; i++) {
        LocalDateTime test = LocalDateTime.ofEpochSecond(i, 500, OFFSET_PTWO);
        assertEquals(test, base.plusSeconds(i));
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:9,代碼來源:TCKLocalDateTime.java

示例12: main

import java.time.LocalDateTime; //導入方法依賴的package包/類
public static void main(String[] args) throws Throwable {
    int N = 10000;
    long t1970 = new java.util.Date(70, 0, 01).getTime();
    Random r = new Random();
    for (int i = 0; i < N; i++) {
        int days  = r.nextInt(50) * 365 + r.nextInt(365);
        long secs = t1970 + days * 86400 + r.nextInt(86400);
        int nanos = r.nextInt(NANOS_PER_SECOND);
        int nanos_ms = nanos / 1000000 * 1000000; // millis precision
        long millis = secs * 1000 + r.nextInt(1000);

        LocalDateTime ldt = LocalDateTime.ofEpochSecond(secs, nanos, ZoneOffset.UTC);
        LocalDateTime ldt_ms = LocalDateTime.ofEpochSecond(secs, nanos_ms, ZoneOffset.UTC);
        Instant inst = Instant.ofEpochSecond(secs, nanos);
        Instant inst_ms = Instant.ofEpochSecond(secs, nanos_ms);
        //System.out.printf("ms: %16d  ns: %10d  ldt:[%s]%n", millis, nanos, ldt);

        /////////// Timestamp ////////////////////////////////
        Timestamp ta = new Timestamp(millis);
        ta.setNanos(nanos);
        if (!isEqual(ta.toLocalDateTime(), ta)) {
            System.out.printf("ms: %16d  ns: %10d  ldt:[%s]%n", millis, nanos, ldt);
            print(ta.toLocalDateTime(), ta);
            throw new RuntimeException("FAILED: j.s.ts -> ldt");
        }
        if (!isEqual(ldt, Timestamp.valueOf(ldt))) {
            System.out.printf("ms: %16d  ns: %10d  ldt:[%s]%n", millis, nanos, ldt);
            print(ldt, Timestamp.valueOf(ldt));
            throw new RuntimeException("FAILED: ldt -> j.s.ts");
        }
        Instant inst0 = ta.toInstant();
        if (ta.getTime() != inst0.toEpochMilli() ||
            ta.getNanos() != inst0.getNano() ||
            !ta.equals(Timestamp.from(inst0))) {
            System.out.printf("ms: %16d  ns: %10d  ldt:[%s]%n", millis, nanos, ldt);
            throw new RuntimeException("FAILED: j.s.ts -> instant -> j.s.ts");
        }
        inst = Instant.ofEpochSecond(secs, nanos);
        Timestamp ta0 = Timestamp.from(inst);
        if (ta0.getTime() != inst.toEpochMilli() ||
            ta0.getNanos() != inst.getNano() ||
            !inst.equals(ta0.toInstant())) {
            System.out.printf("ms: %16d  ns: %10d  ldt:[%s]%n", millis, nanos, ldt);
            throw new RuntimeException("FAILED: instant -> timestamp -> instant");
        }

        ////////// java.sql.Date /////////////////////////////
        // j.s.d/t uses j.u.d.equals() !!!!!!!!
        java.sql.Date jsd = new java.sql.Date(millis);
        if (!isEqual(jsd.toLocalDate(), jsd)) {
            System.out.printf("ms: %16d  ns: %10d  ldt:[%s]%n", millis, nanos, ldt);
            print(jsd.toLocalDate(), jsd);
            throw new RuntimeException("FAILED: j.s.d -> ld");
        }
        LocalDate ld = ldt.toLocalDate();
        if (!isEqual(ld, java.sql.Date.valueOf(ld))) {
            System.out.printf("ms: %16d  ns: %10d  ldt:[%s]%n", millis, nanos, ldt);
            print(ld, java.sql.Date.valueOf(ld));
            throw new RuntimeException("FAILED: ld -> j.s.d");
        }
        ////////// java.sql.Time /////////////////////////////
        java.sql.Time jst = new java.sql.Time(millis);
        if (!isEqual(jst.toLocalTime(), jst)) {
            System.out.printf("ms: %16d  ns: %10d  ldt:[%s]%n", millis, nanos, ldt);
            print(jst.toLocalTime(), jst);
            throw new RuntimeException("FAILED: j.s.t -> lt");
        }
        // millis precision
        LocalTime lt = ldt_ms.toLocalTime();
        if (!isEqual(lt, java.sql.Time.valueOf(lt))) {
            System.out.printf("ms: %16d  ns: %10d  ldt:[%s]%n", millis, nanos, ldt);
            print(lt, java.sql.Time.valueOf(lt));
            throw new RuntimeException("FAILED: lt -> j.s.t");
        }
    }
    System.out.println("Passed!");
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:78,代碼來源:JavatimeTest.java

示例13: setEpochTimeMillis

import java.time.LocalDateTime; //導入方法依賴的package包/類
public void setEpochTimeMillis(long timestamp) throws IOException {
    LocalDateTime localDateTime =
        LocalDateTime.ofEpochSecond(timestamp / 1000, 0, ZoneOffset.UTC);
    setUtcDateTime(localDateTime);
}
 
開發者ID:jpuderer,項目名稱:jpuderer-things-drivers,代碼行數:6,代碼來源:Ds3231Rtc.java

示例14: timestampToDateTime

import java.time.LocalDateTime; //導入方法依賴的package包/類
private static LocalDateTime timestampToDateTime(int timestamp) {
    return LocalDateTime.ofEpochSecond(timestamp, 0, ZoneOffset.UTC);
}
 
開發者ID:CROW-NDOV,項目名稱:displaydirect,代碼行數:4,代碼來源:DisplayDirectMessageParser.java

示例15: factory_ofEpochSecond_badNanos_toSmall

import java.time.LocalDateTime; //導入方法依賴的package包/類
@Test(expectedExceptions=DateTimeException.class)
public void factory_ofEpochSecond_badNanos_toSmall() {
    LocalDateTime.ofEpochSecond(0, -1, OFFSET_PONE);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:5,代碼來源:TCKLocalDateTime.java


注:本文中的java.time.LocalDateTime.ofEpochSecond方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。