java - 时间戳在Java中即时

标签 java time timestamp java.time.instant

<分区>

I have a pojo which has a filed type as Instant. I want to set the Instant getting it from TimsStamp. Would it be possible?

例如:我有一个 java.sql.Timestamp,我想将其转换为 java.time.Instant. 可能吗?

最佳答案

我们已经准备好现有的方法,可以将 Timestamp 转换为 Instant,反之亦然。

    Instant instant = Instant.now(); // get The current time in instant object
    Timestamp t=java.sql.Timestamp.from(instant); // Convert instant to Timestamp
    Instant anotherInstant=t.toInstant();         // Convert Timestamp to Instant

关于java - 时间戳在Java中即时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38365130/

相关文章:

php - 如何使用 PHP 获取时间值(与 Excel 中的 TIMEVALUE() 函数相同)

javascript - 在 JavaScript 中创建 UTC 日期,添加一天,获取 unix 时间戳

java - spring如何为多个api请求管理线程

java - 在 main 函数中一起返回一个数组和一个变量

java - 我如何创建一个具有变量PeriodType的jodatime周期

java - Java中抽象类的继承

java - JDBC - SQL 语句执行时间记录

java - 如何在oracle和java中的时间戳值中保留24小时00分钟

timestamp - KnexJS : How do you insert/update a timestamp field with current timestamp?

javascript - 如何用 Epoch Time 替换 JavaScript 中的 ObjectId