草庐IT

date_validator

全部标签

Java日历问题: why are these two Dates not equal?

importjava.io.*;publicclasstesting{publicstaticvoidmain(Stringa[])throwsException{Dated1=newDate();Thread.sleep(2000);Dated2=newDate();if(d1.equals(d2)){System.out.println("Bothequal");}else{System.out.println("Bothnotequal");}Calendarc1=Calendar.getInstance();Calendarc2=Calendar.getInstance();c

java - Bean Validation 的 resourcebundle 参数化在 JSF 2 中的可能性?

在JSF2中使用带有BV的资源包看起来像这样:publicclassUserBean{@Size(min=13,message="{creditcard.length}")publicStringgetCreditCard(){returnthis.creditCard;}}而且我必须在可以在faces-config.xml中注册的属性文件之一中定义ResourceBundle条目creditcard.length=creditcardlengthmustbeatleast13characters我们可以看到creditcard.length的值是非参数化的。我可以做可以从BV或其他地

java - 字符串 -> java.util.Date -> java.sql.Date(带时间戳)

这是我的问题:我有一个用户输入一个日期,如:2012-12-24(字符串)我将时间连接到该字符串,然后转换为java.util.Date我的代码如下所示:Stringtempstartdate=startdte;//startdteisthestringvaluefromatxtfieldtempstartdate+="00:01:00";Stringtempenddate=startdte;tempenddate+="23:59:59";SimpleDateFormatdf=newSimpleDateFormat("yyyy-MM-ddhh:mm:ss");java.util.Dat

java - 与 Bean Validation API 结合使用时,Hibernate 不遵循 JPA 规范?

这个问题是这个问题的后续问题:JPAConstraintViolationvsRollback我做了一些关于JPA和验证API(JSR-303)组合的测试。我在JPAspecifications中找到了以下内容(第101-102页):Bydefault,thedefaultBeanValidationgroup(thegroupDefault)willbevalidateduponthepre-persistandpre-updatelifecyclevalidationevents...IfthesetofConstraintViolationobjectsreturnedbythe

java - JPA 2.1 : Introducing Java 8 Date/Time API

我想在启用JPA的应用程序中添加对Java8日期/时间API(JSR-310)的支持。很明显JPA2.1doesnotsupporttheJava8Date/TimeAPI.作为解决方法,最常见的建议是使用AttributeConverter.在我现有的应用程序中,我将我的实体更改为对列映射字段使用LocalDate/LocalDateTime类型,并为java.util添加了旧版setter/getter.Date给他们。我创建了相应的AttributeConverter类。当使用Query.setParameter()和java.util.Date实例时,我的应用程序现在失败了(它

java - 在单元测试 Controller 时模拟 Spring Validator

在为另一个项目创建的代码编写单元测试事后分析时,我遇到了如何模拟使用initBinder绑定(bind)到Controller的validator的问题?通常我只会考虑确保我的输入有效,并在validator中进行一些额外的调用,但在这种情况下,validator类与通过一些数据源进行检查相结合,这一切都变得一团糟去测试。耦合可以追溯到使用的一些旧的公共(public)库,并且不在我当前修复所有这些库的工作范围内。起初我尝试使用PowerMock和模拟静态方法来模拟validator的外部依赖性,但最终遇到了一个在创建类时需要数据源的类,但没有找到解决该问题的方法.然后我尝试只使用普通

java - 如何将 util.Date 转换为 time.LocalDate 以正确处理 1893 年之前的日期

我google了一下,最常用的方法好像是date.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();但是,对于1893-04-01之前的日期,此方法似乎会失败以下测试在我的机器上失败,结果为1893-03-31而不是1893-04-01:@TestpublicvoidtestBeforeApril1893()throwsParseException{Datedate=newSimpleDateFormat("yyyy-MM-dd").parse("1893-04-01");System.out.println(date);

java.time : DateTimeParseException for date "20150901023302166"

这个问题在这里已经有了答案:Isjava.timefailingtoparsefraction-of-second?(3个答案)关闭7年前。LocalDateTime.parse("20150901023302166",DateTimeFormatter.ofPattern("yyyyMMddHHmmssSSS"))给出错误:java.time.format.DateTimeParseException:Text'20150901023302166'couldnotbeparsedatindex0

java - Facebook 实时更新 : Validating X-Hub-Signature SHA1 signature in Java

当Facebook发送实时更新时,它们会在HTTPheader中包含一个X-Hub-Signature。根据theirdocumentation,他们使用SHA1和应用程序secret作为key。基于similarquestion对于C#,我尝试像这样验证签名('body'是facebook在请求正文中发送的消息):StringpassedSignature=req.getHeader("X-Hub-Signature").substring(5);Machmac=Mac.getInstance("HmacSHA1");hmac.init(newSecretKeySpec(FACEBO

java - Date.toString() 显示什么时区?

默认情况下,什么时区执行方法java.util.Date.toString()展示?由于JavaDate将给定日期存储在UTC中并且不包含任何明确的时区,Date.toString()只是显示主机的默认时区,或者TimeZone.getDefault()? 最佳答案 它使用TimeZone.getDefault()进行显示,而这又将默认为其运行的操作系统(即主机)的时区。所以在实践中,它们将是同一件事请注意,Java日期并不是真正的日期!它是一个瞬间,由纪元。它仍然包含引用年、月等的方法,但这些都已弃用。您绝不应该像使用日期一样使用