132得票10回答
在Java 8中,有没有将ZoneId转换为ZoneOffset的方法?

我有一个时间戳和一个时区ID(见下面的method1)。 它可以使用系统默认时区ID转换为LocalDateTime,但我没有找到将时间戳转换为LocalDateTime的方法(请参阅下面的method2),因为没有ZoneOffset.systemDefault。 我认为这很难理解。impo...

109得票6回答
如何将Instant转换为LocalDate

我有一个从应该是LocalDate的来源收到的Instant,但在LocalDate类中没有看到任何将Instant转换为LocalDate的方法。 最佳的方法是什么?

60得票5回答
将java.time.Instant转换为没有时区偏移的java.sql.Timestamp

在我正在开发的应用程序中,我需要将java.time.Instant对象转换为java.sql.Timestamp。当我创建Instant对象时,如下所示:Instant now = Instant.now(); 我收到了类似于2017-03-13T14:28:59.970Z这样的东西。当我尝...

58得票5回答
将字符串转换为“Instant”

我尝试使用Java 8或者一个工具包将字符串中的日期时间转换为Instant实例。例如, String requestTime = "04:30 PM, Sat 5/12/2018"; toInstant reqInstant should result in 2018-...

39得票1回答
计算两个时间点之间的天数、小时数和分钟数

我有一个格式为这样的即时对象:DateTimeFormatter formatter = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.SHORT ) .withLoca...

33得票3回答
为什么JPA不支持java.time.Instant?

我认为使用java.time.Instant将日期存储到数据库中是最好的选择:它是最接近TIMESTAMP的时间戳,并且您不需要考虑时区,它只是时间上的瞬间。 JPA支持LocalDate、LocalTime、LocalDateTime等类型,但不支持Instant。当然,您可以使用Attr...

33得票4回答
哪个更推荐:Instant.now().toEpochMilli()还是System.currentTimeMillis()?

在Java中,获取当前时间戳有很多不同的方法,但哪一种方式是建议使用的呢:Instant.now().toEpochMilli()还是System.currentTimeMillis()?

30得票3回答
将Joda时间Instant转换为Java时间Instant

我有一个Instant实例(org.joda.time.Instant),它是在某个API响应中获取的。我还有另一个实例(java.time.Instant) ,它是从其他调用中获取的。现在,我想比较这两个对象,以确定哪一个是最新的。怎样才能做到呢?

21得票1回答
即时时间 vs 带时区的时间

我不太明白在以下示例中应该使用这两者中的哪一个: 我们有一个OfferEntity,其中有一个成员availableDay,它是提供的有效日期。 现在,表格将如下所示:CREATE TABLE IF NOT EXISTS offer ( created timestamp with...

20得票5回答
为什么在java.time.Instant中添加周数不被支持?

以下的代码段:Instant inFourWeeks = Instant.now().plus(4L, ChronoUnit.WEEKS); 抛出一个异常:java.time.temporal.UnsupportedTemporalTypeException: Unsupported unit...