草庐IT

java - 泛型 hell - 如何将 joda.DateTime 传递给 Hamcrest Matcher.greaterThan?

JodaTime有publicfinalclassDateTimeextendsBaseDateTime{...}一直到publicinterfaceReadableInstantextendsComparable哈姆克雷斯特有publicstatic>org.hamcrest.MatchergreaterThan(Tvalue){...}如果我尝试greaterThan(newDateTime());然后我得到一个编译错误(Eclipse给出了大部分线索)ThegenericmethodgreaterThan(T)oftypeMatchersisnotapplicableforthe

java - 转换 Java 8's LocalDateTime to Joda' s LocalDateTime 的简单方法

有什么简单的方法可以将Java8的LocalDateTime转换为Joda的LocalDateTime?其中一种方法是将其转换为字符串,然后从该字符串创建Joda的LocalDateTime。 最佳答案 通过毫秒转换(本质上是一个java.util.Date()):java.time.LocalDateTimejava8LocalDateTime=java.time.LocalDateTime.now();//Separatesteps,showingintermediatetypesjava.time.ZonedDateTimej

java - 使用带时区的 Joda 解析日期

我有两个时间戳,它们以两种不同的格式描述同一时刻。2010-10-0318:58:07和2010-10-03T16:58:07.000+02:00。我使用Joda-Time解析具有两个不同日期格式化程序的时间戳。最后,我想要两个DateTime对象,它们在同一时刻是相等的。DateFormatter提供了多种方法来控制时区和语言环境,但我无法使用它。这是我想要工作的代码:finalStringdate1="2010-10-0318:58:07";//Europe/BerlinlocaltimefinalDateTimeFormatterformatter1=DateTimeFormat

java - 为什么 joda DateTimeZone 的 getOffset() 方法需要一个 "instant"?

我正在尝试做的事情:我试图从DateTimeZone对象获取以毫秒为单位的GMT偏移量。示例:DateTimeZonegmt=//somehowgetgmtzoneobjectlongoffset=gmt.getOffsetSomehow();//expectoffset=0DateTimeZoneny_est=//somehowgetthattimezoneobjectrepresenting"EST"offsetofNYzonelongoffset=ny_est.getOffsetSomehow();//expectoffset=-18000000=-5*60*60*1000Dat

java - 如何在 JPA (eclipselink) 中使用 joda 时间?

我试图在我的entity类中使用DataTime。在字段上方添加@Temporal(TemporalType.DATE),我收到错误提示"ThepersistentfieldorpropertyforaTemporaltypemustbeoftypejava.util.Date,java.util.Calendar或java.util.GregorianCalendar”。我可以来回介绍转换;使用setter和getter如下:@Temporal(TemporalType.DATE)privateCalendarattendanceDate;publicDateTimegetAtten

java - java.util.Date 和 Joda Time API 之间的差异

这个问题在这里已经有了答案:关闭10年前。PossibleDuplicate:ShouldIuseJavadateandtimeclassesorgowitha3rdpartylibrarylikeJodaTime?关于何时值得使用JodaTime而不是基本的java.util.Date类,我可以使用一些指导。有什么好处?JodaTime是否可以让您做Date类不能做的任何事情,还是说它更容易使用还是什么?此外,关于JodaTime是否是标准API的一部分,我看到了相互矛盾的信息。是否标准?

java - Joda-Time 是否有一个名为 isToday 的方法

我需要检查给定的时间戳是否是今天。我正在使用Joda-Time.有没有一种方法或一种简单的方法来检查这个?哪个Joda-Time类更适合这个?LocalDate?DateTime? 最佳答案 日期可以通过一条语句进行比较,所以你为什么需要一个特殊的函数。当dateTime是DateTime()的对象时if((dateTime.toLocalDate()).equals(newLocalDate()))当date是java.util.date的对象时if((newDateTime(date).toLocalDate()).equals

java - Joda 在 GMT 时区解析 ISO8601 日期

我有一个ISO8601日期,比方说:2012-01-19T19:00-05:00我的机器时区是GMT+1我正在尝试使用joda来解析它并将其转换为相应的GMT日期和时间:DateTimeFormattersimpleDateISOFormat=DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mmZZ");creationDate=simpleDateISOFormat.withZone(DateTimeZone.UTC).parseDateTime(date+"T"+time).toDate();现在我期待的结果是FriJan2000:00:00C

java - 将 java.sql.Date 和 java.util.Date 转换为 org.joda.time.LocalDate

我正在尝试仔细、细致地清理我的一些旧(生产)代码。我想做的一件事是将我对java.util.Date的所有用法转换为LocalDate和DateTime。但是,今晚我在工作时注意到了一个很大的障碍。我有这段代码:ResultSetresults=stmt.executeQuery();Datelast=results.getDate("LAST_DELIVERY_DATE");Datenext=results.getDate("NEXT_DELIVERY_DATE");booleanreceived;if(last==null&&next==null){received=true;//

java - 使用 Joda Time 将 DateTime 减去 1 小时

我只想从DateTime中减去1小时我试着在Google上查找它,我发现有一个名为minus的方法可以获取日期的副本并正确获取特定的持续时间这里:http://www.joda.org/joda-time/apidocs/org/joda/time/DateTime.html#minus(long)但我不知道如何使用它,也无法在Internet上找到示例。这是我的代码:Stringstring1=(String)table_4.getValueAt(0,1);Stringstring2=(String)table_4.getValueAt(0,2);DateTimeFormatterd