- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
在Joda Time , 人们可以很容易地使用 DateTimeZone.isLocalDateTimeGap
判断本地日期和时间是否无效的方法,因为它落入了 Spring 夏令时转换所造成的间隙。
DateTimeZone zone = DateTimeZone.forID("America/New_York");
LocalDateTime ldt = new LocalDateTime(2013, 3, 10, 2, 0);
boolean inGap = zone.isLocalDateTimeGap(ldt); // true
但是您如何检测回退转换呢?换句话说,如果本地日期和时间可能因为重叠而变得不明确,您如何检测呢?我希望像 zone.isLocalDateTimeOverlap
这样的东西,但它不存在。如果是这样,我会像这样使用它:
DateTimeZone zone = DateTimeZone.forID("America/New_York");
LocalDateTime ldt = new LocalDateTime(2013, 11, 3, 1, 0);
boolean overlaps = zone.isLocalDateTimeOverlap(ldt); // true
Joda-Time 文档清楚地表明,如果在转换过程中存在重叠,除非另有说明,否则它将采用较早的可能性。但它没有说明如何检测该行为。
最佳答案
利用withEarlierOffsetAtOverlap()
public static boolean isInOverlap(LocalDateTime ldt, DateTimeZone dtz) {
DateTime dt1 = ldt.toDateTime(dtz).withEarlierOffsetAtOverlap();
DateTime dt2 = dt1.withLaterOffsetAtOverlap();
return dt1.getMillis() != dt2.getMillis();
}
public static void test() {
// CET DST rolls back at 2011-10-30 2:59:59 (+02) to 2011-10-30 2:00:00 (+01)
final DateTimeZone dtz = DateTimeZone.forID("CET");
LocalDateTime ldt1 = new LocalDateTime(2011,10,30,1,50,0,0); // not in overlap
LocalDateTime ldt2 = new LocalDateTime(2011,10,30,2,50,0,0); // in overlap
System.out.println(ldt1 + " is in overlap? " + isInOverlap(ldt1, dtz));
System.out.println(ldt2 + " is in overlap? " + isInOverlap(ldt2, dtz));
}
关于java - 如何检测 Joda Time 中不明确的 DST 重叠?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18793411/
我是 grails 的新手。我正在使用 joda 插件来获取日期和时间。所以我在单独的列中显示日期和时间。现在我想使用条件搜索日期。 我在 gsp 页面中使用以下代码来搜索日期。
我试图在执行更多计算之前简单地将 TimeZone 信息添加回 LocalDate。 LocalDate 来自使用 ObjectLab LocalDateCalculator 将天数添加到现有 Dat
所以我在使用 JodaTime 年表 IslamicChronology 解析日期时遇到问题,因此编写了一个小示例来演示我的问题。 代码如下: import org.joda.time.Chronol
当我启动我的应用程序时,virgo 会抛出这样的异常: [2015-09-05 11:27:53.254] TCP Connection(2)-127.0.0.1 Installation of
我使用 Spring 从 Web API rest API 检索 JSON 数据,使用 Jackson Joda 模块反序列化 ISO 日期,并将其转换为 Joda DateTime。 Spring
在 Android 设备 (7.0) 上,出现此崩溃: Fatal Exception: org.joda.time.IllegalInstantException: Illegal instant
我需要将 GMT 转换为亚利桑那时间。亚利桑那州目前有 MST(夏令时关闭)。 但是在 Joda Time DateTimeZone 代码中,MST 已映射到 America/Denver: map.
大家早上好。 我想帮助您了解如何使用 1.2.1.1 版本的 Joda Time 完成 org.joda.time.DateTime 到 java.util.Date 的转换。 为什么选择 Joda
试试这个: @Type(type = "org.jadira.usertype.moneyandcurrency.joda.PersistentMoneyAmountAndCurrency") pri
尝试使用 Joda 将包含日期字符串的 JSON 字符串反序列化为 POJO 时遇到异常。 我将 Jackson2 与 Spring 和 Robospice 一起使用。 我遇到以下异常: Could
我有一个招摇的OpenAPI YAML文件,我想使用gradle-swagger-generator-plugin生成Java 这是我的config.json { "useRxJava2": tr
我想使用以下 MDX 语句: with member [x] as now()->plusMonths(1)->withDayOfMonth(1)->minusDay(1) select [x] on
System.out.println( PeriodFormat.getDefault().print(Period.hours(1).plusMinutes(30).plusSeconds(60))
我正在使用 Joda-Time Duration 来获取两个 DateTime 之间的持续时间: DateTime startTimeDate = new DateTime(startTimeDate
当我运行以下代码片段时: import org.joda.time.DateTime; import org.joda.time.DateTimeZone; import java.sql.Times
我正在尝试在 Joda DateTime 中转换毫秒。米利斯是 1338501600000我使用了在线转换器和其他库,所有结果都是 1338501600000 millis 是 Fri Jun 01
我尝试使用以下代码,但收到错误格式无效:“12/11/2013”: String dFrom = ps.utils.gv(request, "dFrom"); String dTo = ps.ut
我正在尝试使用 Joda-Time 的持续时间类来计算两天之间的确切天数差异。这意味着我希望结果是 25.48 天,而不是仅仅 25 天。现在我有: private static final doub
有没有隐藏的方法来获得 Joda-Time以分钟为单位的时间段(或任何其他) 现在我做的是: (period.getHours()*60 + period.getMinutes() + roundTw
有谁知道如何解析日期,例如:Mon Aug 04 16:07:00 CEST 2014使用 Joda 的 DateTime 格式化程序转换为 dd/MM/YYYY HH:MM:SS。我已经尝试过了:
我是一名优秀的程序员,十分优秀!