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


Java Timestamp.from方法代码示例

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


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

示例1: increment

import java.sql.Timestamp; //导入方法依赖的package包/类
/**
 * Increase the progress of a given player
 *
 * @param player Player
 * @param amount Amount
 */
public void increment(UUID player, int amount)
{
    AchievementProgress progress = this.progress.get(player);

    if (progress == null)
    {
        progress = new AchievementProgress(-1, 0, Timestamp.from(Instant.now()), null, true);
        this.progress.put(player, progress);
    }

    if (progress.getProgress() + amount > this.objective && progress.getUnlockTime() == null)
    {
        progress.unlock();
        progress.setProgress(this.objective);
        this.sendRewardMessage(player);
    }
    else if (progress.getUnlockTime() == null)
    {
        progress.setProgress(progress.getProgress() + amount);
    }
}
 
开发者ID:SamaGames,项目名称:SamaGamesAPI,代码行数:28,代码来源:IncrementationAchievement.java

示例2: unlock

import java.sql.Timestamp; //导入方法依赖的package包/类
/**
 * Unlock this achievement for a given player
 *
 * @param player Player
 */
public void unlock(UUID player)
{
    if (this instanceof IncrementationAchievement)
        throw new IllegalStateException("Try to unlock incrementation achievement");

    AchievementProgress progress = this.progress.get(player);

    if (progress != null && progress.getUnlockTime() != null)
        return;

    if (progress == null)
    {
        progress = new AchievementProgress(-1, 0, Timestamp.from(Instant.now()), null, true);
        this.progress.put(player, progress);
    }

    progress.unlock();
    progress.setProgress(1);

    this.sendRewardMessage(player);
}
 
开发者ID:SamaGames,项目名称:SamaGamesAPI,代码行数:27,代码来源:Achievement.java

示例3: convertToDatabaseColumn

import java.sql.Timestamp; //导入方法依赖的package包/类
@Override
public Timestamp convertToDatabaseColumn(final Instant instant) {
    if (instant == null) {
        return null;
    }
    return Timestamp.from(instant);
}
 
开发者ID:minijax,项目名称:minijax,代码行数:8,代码来源:InstantConverter.java

示例4: deserialize

import java.sql.Timestamp; //导入方法依赖的package包/类
@Override
public VrijBericht deserialize(final JsonParser jp, final DeserializationContext ctxt) throws IOException {
    final ObjectCodec oc = jp.getCodec();
    final JsonNode node = oc.readTree(jp);

    final Integer id = JsonUtils.getAsInteger(node, "id");
    VrijBericht vrijBericht;
    if (id != null) {
        // Bij een bestaand vrij bericht alleen indicatieGelezen aanpassen.
        vrijBericht = entityManager.find(VrijBericht.class, id);
        final String ongelezen = JsonUtils.getAsString(node, "ongelezen");
        boolean gelezen;
        switch (ongelezen) {
            case "Nee":
                gelezen = true;
                break;
            case "Ja":
            default:
                gelezen = false;
        }
        vrijBericht.setIndicatieGelezen(gelezen);
    } else {
        final Short soortvrijberId = JsonUtils.getAsShort(node, "soortvrijber");
        final String data = JsonUtils.getAsString(node, "data");
        final SoortVrijBericht soortVrijBericht = entityManager.getReference(SoortVrijBericht.class, soortvrijberId);
        vrijBericht =
                new VrijBericht(SoortBerichtVrijBericht.STUUR_VRIJ_BERICHT, soortVrijBericht,
                        Timestamp.from(DatumUtil.nuAlsZonedDateTimeInNederland().toInstant()), data, null);
        final ArrayNode partijen = (ArrayNode) node.get("partijen");
        for (JsonNode partijNode : partijen) {
            final Short partijId = Short.valueOf(partijNode.asText());
            final VrijBerichtPartij vrijBerichtPartij = new VrijBerichtPartij(vrijBericht, partijRepository.findOne(partijId));
            vrijBericht.getVrijBerichtPartijen().add(vrijBerichtPartij);
        }
    }
    return vrijBericht;
}
 
开发者ID:MinBZK,项目名称:OperatieBRP,代码行数:38,代码来源:VrijBerichtDeserializer.java

示例5: test45

import java.sql.Timestamp; //导入方法依赖的package包/类
@Test
public void test45() throws Exception {
    Timestamp ts1 = Timestamp.valueOf("1961-08-30 00:00:00");
    Instant instant = ts1.toInstant();
    Timestamp ts2 = Timestamp.from(instant);
    assertTrue(ts1.equals(ts2), "Error ts1 != ts2");
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:8,代码来源:TimestampTests.java

示例6: test46

import java.sql.Timestamp; //导入方法依赖的package包/类
@Test
public void test46() throws Exception {
    Instant instant = Instant.now();
    Timestamp ts2 = Timestamp.from(instant);
    assertTrue(instant.equals(ts2.toInstant()),
            "Error Instant values do not match");
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:8,代码来源:TimestampTests.java

示例7: findEvents

import java.sql.Timestamp; //导入方法依赖的package包/类
public List<Event> findEvents(Optional<Interval> withIn) {
    StringBuilder qs = new StringBuilder("select e from Event e");
    if (withIn.isPresent()) {
        qs.append(" and t.lastModifiedTime>:startsAt and t.lastModifiedTime<:endsAt");
    }
    TypedQuery<Event> q = em.createQuery(qs.toString(), Event.class);
    if (withIn.isPresent()) {
        Timestamp ts = Timestamp.from(withIn.get().getStart().toInstant());
        q.setParameter("startsAt", ts);
        Timestamp te = Timestamp.from(withIn.get().getEnd().toInstant());
        q.setParameter("endsAt", te);
    }
    return q.getResultList();
}
 
开发者ID:psd2-in-a-box,项目名称:mid-tier,代码行数:15,代码来源:CustomerArchivist.java

示例8: getTransactions

import java.sql.Timestamp; //导入方法依赖的package包/类
/**
 * getting a set of transactions filtered according to the APi capabilities
 *
 * @param elementSet the number of element that is wished returned
 * @param withIn     the interval which the returned items needs to stay within
 * @param sortAs     attribute to sort by, default is time and supports sorting by amount
 */
public List<Transaction> getTransactions(String regNo, String accountNo, Optional<Element> elementSet, Optional<Interval> withIn,
        List<Sort> sortAs) {
    StringBuilder qs = new StringBuilder("select t from Transaction t where t.account.regNo=:regNo and t.account.accountNo=:accountNo");
    if (withIn.isPresent()) {
        qs.append(" and t.lastModifiedTime>:startsAt and t.lastModifiedTime<:endsAt");
    }
    sortAs.stream()
            .filter(sort -> "amount".equals(sort.getAttribute()))
            .findAny()
            .ifPresent(sort -> qs.append(" order by t.").append(sort.getAttribute()).append(" ").append(sort.getDirection()));
    TypedQuery<Transaction> q = em.createQuery(qs.toString(), Transaction.class);
    q.setParameter("regNo", regNo);
    q.setParameter("accountNo", accountNo);
    if (withIn.isPresent()) {
        Timestamp ts = Timestamp.from(withIn.get().getStart().toInstant());
        q.setParameter("startsAt", ts);
        Timestamp te = Timestamp.from(withIn.get().getEnd().toInstant());
        q.setParameter("endsAt", te);
    }
    List<Transaction> txs = q.setMaxResults(TX_MAXSIZE).getResultList();
    if ((TX_DEFAULTSIZE < txs.size() && (elementSet.isPresent()))) {
        return reduceElements(elementSet.get(), txs);
    }
    return txs;

}
 
开发者ID:psd2-in-a-box,项目名称:mid-tier,代码行数:34,代码来源:AccountArchivist.java

示例9: unlock

import java.sql.Timestamp; //导入方法依赖的package包/类
/**
 * Internal
 * Unlock achievement
 */
void unlock()
{
    this.unlockTime = Timestamp.from(Instant.now());
    this.changed = true;
}
 
开发者ID:SamaGames,项目名称:SamaGamesAPI,代码行数:10,代码来源:AchievementProgress.java

示例10: main

import java.sql.Timestamp; //导入方法依赖的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

示例11: convertToDatabaseColumn

import java.sql.Timestamp; //导入方法依赖的package包/类
@Override
public java.sql.Timestamp convertToDatabaseColumn(ZonedDateTime entityValue) {
   return Timestamp.from(entityValue.toInstant());
}
 
开发者ID:mintster,项目名称:nixmash-blog,代码行数:5,代码来源:ZoneDateTimeConverter.java

示例12: test47

import java.sql.Timestamp; //导入方法依赖的package包/类
@Test(expectedExceptions = NullPointerException.class)
public void test47() throws Exception {
    Instant instant = null;
    Timestamp.from(instant);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:6,代码来源:TimestampTests.java

示例13: slaSelectieTaakOp

import java.sql.Timestamp; //导入方法依赖的package包/类
@Override
public SelectieTaakDTO slaSelectieTaakOp(SelectieTaakDTO selectieTaak) {
    Dienst dienst = referentieRepository.getReferentie(Dienst.class, selectieTaak.getDienstId());
    ToegangLeveringsAutorisatie
            tla =
            referentieRepository.getReferentie(ToegangLeveringsAutorisatie.class, selectieTaak.getToegangLeveringsautorisatieId());
    Selectietaak entiteit;
    if (selectieTaak.getId() == null) {
        entiteit = new Selectietaak(dienst, tla, selectieTaak.getVolgnummer());
        entiteit.setActueelEnGeldig(true);
    } else {
        entiteit = selectieTaakRepository.vindSelectietaak(selectieTaak.getId());
    }
    entiteit.setDatumPlanning(
            DatumUtil.vanDatumNaarInteger(Optional.ofNullable(selectieTaak.getDatumPlanning()).orElse(selectieTaak.getBerekendeSelectieDatum())));
    entiteit.setVolgnummer(selectieTaak.getVolgnummer());
    entiteit.setActueelEnGeldigStatus(true);
    Selectietaak finalEntiteit = entiteit;
    Optional.ofNullable(selectieTaak.getPeilmomentFormeelResultaat())
            .ifPresent(p -> finalEntiteit.setPeilmomentFormeelResultaat(DatumUtil.vanZonedDateTimeNaarSqlTimeStamp(p)));
    Optional.ofNullable(selectieTaak.getPeilmomentMaterieelResultaat())
            .ifPresent(p -> finalEntiteit.setPeilmomentMaterieelResultaat(DatumUtil.vanDatumNaarInteger(p)));
    // historierecord selectietaak
    Timestamp tsreg = Timestamp.from(ZonedDateTime.now().toInstant());
    SelectietaakHistorie historie = new SelectietaakHistorie(entiteit);
    historie.setDatumPlanning(entiteit.getDatumPlanning());
    historie.setDatumUitvoer(entiteit.getDatumUitvoer());
    historie.setIndicatieSelectielijstGebruiken(Optional.ofNullable(entiteit.isIndicatieSelectielijstGebruiken()).orElse(false));
    historie.setPeilmomentMaterieelResultaat(entiteit.getPeilmomentMaterieelResultaat());
    historie.setPeilmomentFormeelResultaat(entiteit.getPeilmomentFormeelResultaat());
    historie.setDatumTijdRegistratie(tsreg);
    entiteit.getSelectietaakHistorieSet().stream().filter(h -> h.getSelectietaak().getId().equals(finalEntiteit.getId()) && h.getDatumTijdVerval() == null)
            .findFirst()
            .ifPresent(h -> h.setDatumTijdVerval(tsreg));
    entiteit.getSelectietaakHistorieSet().add(historie);
    if (entiteit.getId() == null || statusGewijzigd(entiteit, selectieTaak)) {
        // historierecord selectiestatus
        final SelectietaakStatusHistorie statusHistorie = new SelectietaakStatusHistorie(entiteit);
        statusHistorie.setDatumTijdRegistratie(tsreg);
        statusHistorie.setStatusGewijzigdDoor("Systeem");
        statusHistorie.setStatus(selectieTaak.getStatus());
        statusHistorie.setStatusToelichting(selectieTaak.getStatusToelichting());
        entiteit.getSelectietaakStatusHistorieSet().stream()
                .filter(h -> h.getSelectietaak().getId().equals(finalEntiteit.getId()) && h.getDatumTijdVerval() == null).findFirst()
                .ifPresent(h -> h.setDatumTijdVerval(tsreg));
        entiteit.getSelectietaakStatusHistorieSet().add(statusHistorie);
        //update a-laag
        entiteit.setStatus(selectieTaak.getStatus());
        entiteit.setStatusToelichting(selectieTaak.getStatusToelichting());
    }
    if (selectieTaak.getId() == null) {
        entiteit = selectieTaakRepository.slaOp(entiteit);
    }
    selectieTaak.setId(entiteit.getId());
    return selectieTaak;
}
 
开发者ID:MinBZK,项目名称:OperatieBRP,代码行数:57,代码来源:SelectieTaakServiceImpl.java

示例14: toSqlTimestamp

import java.sql.Timestamp; //导入方法依赖的package包/类
private Timestamp toSqlTimestamp(Instant now) {
    if (now == null) {
        return null;
    }
    return Timestamp.from(now);
}
 
开发者ID:zalando-nakadi,项目名称:nakadi-producer-spring-boot-starter,代码行数:7,代码来源:EventLogRepositoryImpl.java

示例15: timestampOf

import java.sql.Timestamp; //导入方法依赖的package包/类
/**
 * Gets Timestamp for Instant.
 *
 * @param time Time object to be converted.
 * @return Timestamp representing time
 */
private static Timestamp timestampOf(final Instant time) {
    return Timestamp.from(time);
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:10,代码来源:DateTimeUtils.java


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