草庐IT

work_date

全部标签

Java 日历 : Getting Difference Between Two Dates/Times - Off by One

我看过很多关于这个主题的问题和答案,但没有一个能解决我的特定问题。我扩展了javaCalendar类(标准——没有第三方库),并且需要找出两个任意日期之间的天差异。方法:将两个日期的时间都改为午夜。将日期转换为毫秒。找出两个日期之间的差异。将结果除以一天中的毫秒数(24*60*60*1000)。结果应该是天数之差。有时是,有时不是。即使是同一天的考试也可能相差一个。怎么回事? 最佳答案 JodaTime图书馆对此类问题有很好的支持:LocalDated1=newLocalDate(calendar1.getTimeInMillis(

java - 使用 java.util.Date 获取过去的日期

下面是我用来访问10天前过去日期的代码。输出是今天的日期“20130103”。我怎样才能返回今天的日期-10天?我只能使用内置的Java日期类,所以不能使用joda时间。packagepast.date;importjava.text.DateFormat;importjava.text.SimpleDateFormat;importjava.util.Date;publicclassPastDate{publicstaticvoidmain(Stringargs[]){DateFormatdateFormat=newSimpleDateFormat("yyyyMMdd");Datem

java - Date.getTime() 不包括时间?

无法理解为什么会发生以下情况:Stringdate="06-04-200707:05";SimpleDateFormatfmt=newSimpleDateFormat("MM-dd-yyyyHH:mm");DatemyDate=fmt.parse(date);System.out.println(myDate);//MonJun0407:05:00EDT2007longtimestamp=myDate.getTime();System.out.println(timestamp);//1180955100000--wherearethemilliseconds?//ontheother

java - 如何在 java.util.Date 中获取当前季度的第一个日期和最后一个日期

我需要获取当前季度的第一天作为java.util.Date对象,当前季度的最后日期作为java.util。日期对象。我正在使用以下方法获取本月的第一个日期和本月的最后一个日期。privateDategetThisMonthFirstDate(){Calendarcalendar=newGregorianCalendar();calendar.set(Calendar.HOUR_OF_DAY,0);calendar.set(Calendar.MINUTE,0);calendar.set(Calendar.SECOND,0);calendar.set(Calendar.MILLISECON

java - GWT : how to get regex(Pattern and Matcher) working in client side

我们使用GWT2.03和SmartGWT2.2。我正在尝试在客户端代码中匹配如下所示的正则表达式。Patternpattern=Pattern.compile("\\\"(/\d+){4}\\\"");StringtestString1="[\"/2/4/5/6/8\",\"/2/4/5/6\"]";StringtestString2="[]";Matchermatcher=pattern.matcher(testString1);booleanresult=false;while(matcher.find()){System.out.println(matcher.group());

java - 通过使用 java.util.Date 可能出现下溢错误

这段代码:packagetest;importjava.util.Date;publicclassDateUnderflow{publicstaticvoidmain(String[]args){Longtimestamp=-8120649749785140250L;System.out.println(newDate(timestamp));}}产生以下输出:"SatAug0310:00:59CET257325894"怎么会?无一异常(exception)的下溢?Doc说Date(longdate)的date参数是自纪元以来的毫秒数,所以我有点惊讶地发现自己如此深入future..我

java - Spring 数据休息 : RepositoryRestController deserialization from URI not working

我的问题是从URI字符串反序列化实体。当我使用由SpringDataRest生成的HTTP接口(interface)时,一切正常。我可以针对我的端点/api/shoppingLists发布以下JSON,它将被反序列化为以管理员为所有者的购物list。{"name":"Test","owners":["http://localhost:8080/api/sLUsers/admin"]当我使用自定义RepositoryRestController时,这不再起作用。如果我将完全相同的JSON发布到相同的端点,我会收到此响应。{"timestamp":"2015-11-15T13:18:34.

java - Play Framework 2.3.7 : Static assets location not working in production

我看到了一些关于此的问题,但似乎无法深入了解。我有一个PlayFramework2.3.7(Activator1.2.12)站点,当我在开发模式下运行它时一切正常。当我在生产模式下启动它时,出现以下错误:[app]$start[info]WroteC:\Users\App\git\website2.0\target\scala-2.10\app_2.10-1.0-SNAPSHOT.pom[info]MainScalaAPIdocumentationtoC:\Users\App\git\website2.0\target\scala-2.10\api...[info]Compiling5

java - NetBeans 7.0、JUnit 和 Glassfish Embedded 3.1 : Does not work

我正在尝试在Win7Professional机器上使用NB7.0、JUnit和嵌入式GlassfishServer对J2EEWeb应用程序进行JUnit测试。我将其分解为仅使用单个sessionBean测试一个简单的Hello-WorldWeb应用程序。我的类路径中有glasfish-embedded-static-shell.jar,也尝试使用glassfish-embedded-all-3.1,但它也没有用。现在这是我用来测试bean的代码:importjavax.ejb.embeddable.EJBContainer;importorg.junit.AfterClass;impo

java - 使用 Date 或 List 在简单的 getter 和 setter 方法中解决 Sonar 问题

我编写这个getter/setter以从Eclipse源菜单中列出:publicDategetDate(){returndate;}publicvoidsetDate(Datedate){this.date=date;}Sonar报告两个问题:Returnacopyof"date"&Storeacopyof"date"有解释"Mutablemembersshouldnotbestoredorreturneddirectly"和示例代码:publicString[]getStrings(){returnstrings.clone();}publicvoidsetStrings(Strin