草庐IT

date-math

全部标签

java - date_trunc org.postgresql.util.PSQLException : ERROR: syntax error at or near "$1"

我在运行此Java/JDBC代码时遇到此错误。任何想法如何解决它?好像是在提示date_trunc函数中的参数?org.postgresql.util.PSQLException:错误:“$1”处或附近的语法错误排名:100atorg.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2161)atorg.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1890)atorg.

java - Thymeleaf:使用#dates.format() 函数来格式化具有国际化的日期。

我正在使用Thymeleaf#dates.format()函数在View层中格式化日期。我为pic日期格式创建了一个国际化属性文件。我正在使用#dates.format(date,(#{app.dateformat}))这样的函数。但是Thymeleaf抛出一个解析异常。因为thymeleaf现在解析app.dateformat。我如何在thymeleaf中使用日期格式国际化方式。以下是一个异常(exception):org.springframework.expression.spel.SpelParseException:EL1043E:(pos37):Unexpectedtoke

java - 重载 Math.sqrt : overloading method seems to hide the original one

尝试为int类型重载java.lang.Math.sqrt静态方法:importstaticjava.lang.Math.sqrt;classTest{privatestaticdoublesqrt(intn){returnsqrt(1.0*n);}publicstaticvoidmain(String[]args){System.out.println(sqrt(1));}}出现一个奇怪的错误:Test.java:7:sqrt(int)inTestcannotbeappliedto(double)returnsqrt(1.0*n);^1error但是当显式引用java.lang.Ma

java - 无法使用 @DateTimeFormat(模式 ="dd/MM/yyyy")转换 java.util.Date 中的字符串

我有一个带有日期字段的简单POJO。我想将对象与表单中的值绑定(bind)。在表单中,我使用的是日期格式为("dd/mm/yyyy")的jqueryuidatepicker我有console.log值,它是一个字符串:13-11-2014我正在使用spring4.0.7我依赖于joda-time2.5我得到这个异常:Failedtoconvertpropertyvalueoftype'java.lang.String'torequiredtype'java.util.Date'forproperty'endDate';nestedexceptionisorg.springframewo

java - 如何在 java 中使用 apache math 3.0 为直方图生成 bins?

我一直在寻找使用apache通用数学3.0为特定数据集生成bins(通过指定下限、上限和所需的bin数量)。我看过频率http://commons.apache.org/math/apidocs/org/apache/commons/math3/stat/Frequency.html但它并没有给我我想要的东西..我想要一种方法来给我一个区间内值的频率(例如:0到5之间有多少个值)。有什么建议或想法吗? 最佳答案 这是使用ApacheCommonsMath3实现直方图的简单方法:finalintBIN_COUNT=20;double[

java - 更快地实现 Math.round?

此代码是否有任何缺点,它似乎是java.lang.Math.round的更快(且正确)版本?publicstaticlonground(doubled){if(d>0){return(long)(d+0.5d);}else{return(long)(d-0.5d);}}它利用了在Java中将长轮截断为零这一事实。 最佳答案 有一些specialcases内置方法处理,您的代码不处理。来自文档:如果参数为NaN,则结果为0。如果参数为负无穷大或任何小于或等于Integer.MIN_VALUE值的值,则结果等于Integer.MIN_V

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 - 字符串 -> 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

c# - Java 和 C# 中的 Math "pow"返回的结果略有不同?

我正在将程序从C#移植到java。我面对的事实是JavaMath.pow(0.392156862745098,1./3.)=0.7319587495200227C#Math.Pow(0.392156862745098,1.0/3.0)=0.73195874952002271最后一位数字会导致进一步计算出现足够的差异。有什么方法可以模拟c#的pow吗?谢谢 最佳答案 只是为了确认ChrisShain写的内容,我得到了相同的二进制值://JavapublicclassTest{publicstaticvoidmain(String[]a

java - 为什么 anyValue 是 double 值时 Sonar 中的 anyValue % 1 "silly math"?

SonarQube提出重大违规Sillymathshouldnotbeperformed在我的代码中。描述说Certainmathoperationsarejustsillyandshouldnotbeperformedbecausetheirresultsarepredictable.Inparticular,anyValue%1issillybecauseitwillalwaysreturn0.但在我的例子中,anyValue是一个double值。这有效asintended为了我。这是实际的代码:doublev=Double.parseDouble(Utils.formatDoub