草庐IT

datetime-format

全部标签

java - 使用 Jackson 在 json 中以毫秒为单位的 ISO8601

importcom.fasterxml.jackson.databind.util.ISO8601DateFormat;objectMapper.setDateFormat(newISO8601DateFormat());很好,但这会忽略毫秒,我如何在不使用非线程安全的SimpleDateFormatter的情况下将它们放入日期中?https://github.com/FasterXML/jackson-databind/blob/master/src/main/java/com/fasterxml/jackson/databind/util/ISO8601DateFormat.jav

java.time.format.DateTimeFormatter.RFC_1123_DATE_TIME 无法解析时区名称

我正在尝试从定义为使用RFC1123兼容日期时间规范的数据源解析时间戳。我的代码是:value=Instant.from(DateTimeFormatter.RFC_1123_DATE_TIME.parse(textValue));这对某些数据工作正常,但我得到包含区域名称的字符串的异常,即使是在RFC2822中定义的字符串(它从RFC1123间接引用,因为它废弃了RFC822)。示例:java.time.format.DateTimeParseException:Text'Sun,20Aug201700:30:00UT'couldnotbeparsedatindex26java.ti

java - 使用 String.format() 作为注释属性值

我有一个包含许多常量的类:publicclassSecurityConstants{privatestaticfinalStringHAS_ROLE_TEMPLATE="hasRole('%s')";publicstaticfinalStringROLE_USER_INTERNAL="ROLE_USER_INTERNAL";publicstaticfinalStringHAS_ROLE_USER_INTERNAL=String.format(HAS_ROLE_TEMPLATE,ROLE_USER_INTERNAL);}如果我随后尝试使用HAS_ROLE_USER_INTERNAL作为@

java - Spring 无法识别 DateTime 字段的格式

我正在使用Spring3.2.4开发Web应用程序。我有一些表格,其中包含日期和时间的字段。我的一段jsp:......正常形式,没什么特别的。我正在使用日期选择器,它以yyyy-MM-ddHH:mm格式提供日期,所以我将其添加到我的Controller中:@InitBinderpublicvoidinitBinder(WebDataBinderwebDataBinder){SimpleDateFormatdateFormat=newSimpleDateFormat("yyyy-MM-ddHH:mm");dateFormat.setLenient(true);webDataBinder

dd-MMM-yyyy 格式的 java.time.format.DateTimeParseException

这个问题在这里已经有了答案:Howtoparsecase-insensitivestringswithJSR-310DateTimeFormatter?(3个答案)关闭6年前。我正在尝试解析dd-MMM-yyyy格式的日期。packagecom.company;importjavax.swing.text.DateFormatter;importjava.time.format.DateTimeFormatter;importjava.time.*;importjava.util.Locale;publicclassMain{publicstaticvoidmain(String[]a

java - 如何在没有毫秒的情况下打印 DateTime

这个问题在这里已经有了答案:HowtoremovemillisecondsfromDateObjectformatinJava(8个答案)关闭7年前。我正在从一个文件中读取数据,并且需要在经过一些计算后将其序列化到其他地方。我怎样才能在没有毫秒的情况下打印以下内容,以便传递给DateTime.parse的字符串和输出的内容相同?System.out.println(DateTime.parse("2015-06-06T01:51:49-06:00").toString())2015-06-06T01:51:49.000-06:00

java - 错误 : Attempted to call method "format" on null context object

Spring-bootv1.4.1Javav1.8Thymeleafv2.1.5。下面这行代码在我看来:它具有我基于S.O.的语法。问题SpringBootThymeleafOrdinalNumbers,产生错误:org.springframework.expression.spel.SpelEvaluationException:EL1011E:(pos11):Methodcall:Attemptedtocallmethodformat(java.time.LocalDate,java.lang.String)onnullcontextobject但是,如果我在没有Thymeleaf

java - 我怎么知道 Joda DateTime 是否在下午 4 点到晚上 8 点之间?

我想检查给定的日期时间是凌晨4点到早上8点之间还是凌晨12点到凌晨3点之间。这样做的正确方法是什么?这似乎可以解决问题:DateTimestart=newDateTime().withHourOfDay(4);DateTimeend=newDateTime().withHourOfDay(8);Intervalinterval=newInterval(start,end);if(interval.contains(now))returntrue;有没有更好的办法? 最佳答案 只需使用getHourOfDay()inthour=new

java - Joda - 如何在不忽略时区的情况下比较两个 DateTime 对象

我很难比较在不同时区的两个DateTime对象。我已经知道的:1)我知道"isBefore()"方法不将时区考虑在内。因此,下面的“如果”条件不成立(尽管我希望它成立):longaRandomTimeSinceTheEpoch=1234567789L;StringTIMEZONE_SYDNEY_AUSTRALIA="Australia/Sydney";DateTimeZonesydneyTimeZone=DateTimeZone.forID(TIMEZONE_SYDNEY_AUSTRALIA);ChronologychronologySydney=GJChronology.getIns

java - 无法解析 DateTime - 由于时区偏移转换(欧洲/柏林)导致的非法时刻

为什么我无法解析以下日期?DateTime.parse("2015-03-2902:35:00",DateTimeFormat.forPattern("yyyy-MM-ddHH:mm:ss"));结果:org.joda.time.IllegalInstantException:Cannotparse"2015-03-2902:35:00":Illegalinstantduetotimezoneoffsettransition(Europe/Berlin)atorg.joda.time.format.DateTimeParserBucket.computeMillis(DateTimeP