出于某些原因,我们现在不能使用java 8 - 我们仍然坚持使用java 7.
但是,我现在想JSR-310 date/time APIs使用官方的后端ThreeTen来使用新版本.
其主页说明:
The backport is NOT an implementation of JSR-310, as that would require
jumping through lots of unnecessary hoops. Instead, this is a simple backport
intended to allow users to quickly use the JSR-310 API on Java SE 6 and 7.
Run Code Online (Sandbox Code Playgroud)
问题:
您对ThreeTen 的体验是什么?有一些缺点吗?
与官方实施相比,该项目的兼容性如何JSR-310?
从ThreeTen 迁移到官方Java 8实现需要多少工作?
是否值得现在迁移到ThreeTen,后来迁移到JSR-310 - 或者是否有人要等到java 8才能使用,这是否会跳过ThreeTen?
我在我正在使用的服务的反序列化过程中使用的类中有以下字段.
private ZonedDateTime transactionDateTime;
Run Code Online (Sandbox Code Playgroud)
我正在使用的服务可能会使用以下模式返回Date或DateTime: yyyy-MM-dd'T'HH:mm:ss.SSSZ
让我举两个服务返回的例子:
虽然第一个工作正常,但后者导致在反序列化期间抛出以下异常:
java.time.format.DateTimeParseException:无法在索引23处解析文本'2015-11-18T00:00:00.000 + 0200'
我正在使用;
这需要自定义反序列化类吗?
这样的方法是ChronoUnit.HOURS.between(start, end)返回long所以我不能从那里得到分数.
是否有一种可以返回分数的替代方法/方法?
我正在使用Spring Boot开发API,并且正在使用Jackson进行有效负载(反序列化)。我想将ISO-8601格式的日期java.time.Instant时间反序列化为,但不希望从以毫秒或纳秒为单位的时间开始反序列化。我只想支持以一种格式提供给我的API的数据,以减少客户端错误的机会。
目前,Jackson从ISO-8601格式的字符串和仅包含数字的字符串(例如)中反序列化为Instant "20190520"。
我可以在Instant字段中使用Jackson注释,还是可以设置属性以应用这种行为?还是自定义解串器是我唯一的选择?
我正在使用 jersey 客户端进行一些 PoC 来使用 REST 服务,但我在使用 LocalDateTime 格式的字段时遇到了问题。REST 服务响应如下:
{
"id": 12,
"infoText": "Info 1234",
"creationDateTime": "2001-12-12T13:40:30"
}
Run Code Online (Sandbox Code Playgroud)
和我的实体类:
package com.my.poc.jerseyclient;
import java.time.LocalDateTime;
public class Info {
private Long id;
private String infoText;
private LocalDateTime creationDateTime;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getInfoText() {
return infoText;
}
public void setInfoText(String infoText) {
this.infoText = infoText;
}
public LocalDateTime getCreationDateTime() {
return creationDateTime;
}
public void setCreationDateTime(LocalDateTime creationDateTime) …Run Code Online (Sandbox Code Playgroud) 我需要一个表示年,月,周,日,小时,分钟,秒的间隔数据类型.前三个(年,月,日)可以完成,Period最后三个(小时,分钟,秒)可以完成,Duration但是它们似乎都没有.理想情况下,我希望避免实现自定义TemporalAmount.
我知道我可以使用以下方法将 Spring MVC 表单 bean 绑定到 LocalDateTime:
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)
private LocalDateTime startTime;
Run Code Online (Sandbox Code Playgroud)
这会将 String like2016-01-11T15:05:05.123Z转换为LocalDateTime对象。
我在这里找到了一些文档:http : //blog.codeleak.pl/2014/06/spring-4-datetimeformat-with-java-8.html
我找不到如何对java.time.Duration. 我该怎么做呢?
似乎新的java.timeAPI提供了所有内容java.util.Date以及更多内容.自Java 8以来新的API出现时
是否有任何理由使用?应和完全避免?java.util.Datejava.timejava.util.Datejava.util.Calendar
我目前正在开发一个最低API版本为17(JellyBean)的Android Studio项目,因此我无法使用该java.time软件包.相反,我正在使用Android(com.jakewharton.threetenabp:threetenabp:1.1.0)的ThreeTen backport .
我的问题是每个类com.threeten.bp匹配一个java.time,我发现很容易意外导入错误的类,因为自动完成弹出窗口java.time首先显示该选项.我需要一种方法来java.time从我的项目中删除该包,或者至少告诉Android Studio忽略它.有可能吗?
为什么java.time.Clock有区域信息?从时钟中你只能Instant在调用instant()方法时获得- 这是一个没有区域信息的时间.
唯一的目的是让时区中的区域可用,例如像这样创建ZonedDateTime吗?
ZonedDateTime.ofInstant(clock().instant(), clock().getZone())
那么zonedDateTime()在Clock类中有一个方法会不会有意义呢?
jsr310 ×10
java ×9
jackson ×3
java-time ×3
java-8 ×2
threetenbp ×2
android ×1
datetime ×1
jersey ×1
json ×1
rest ×1
spring ×1
spring-boot ×1
spring-mvc ×1
timezone ×1