请包括nanos,否则它将是微不足道的:
long diff = Math.abs(t1.getTime () - t2.getTime ());
Run Code Online (Sandbox Code Playgroud)
[编辑]我想要最精确的结果,所以没有双打; 只有整数/长整数.此外,结果必须是积极的.伪代码:
Timestamp result = abs (t1 - t2);
Run Code Online (Sandbox Code Playgroud)
例子:
t1 = (time=1001, nanos=1000000), t2 = (time=999, nanos=999000000)
-> diff = (time=2, nanos=2000000)
Run Code Online (Sandbox Code Playgroud)
是的,java.sql.Timestamp中的毫秒数在时间和纳米标准中重复,因此1001毫秒表示1秒(1000)和1毫米,它在time部分和nanos部分中因为1毫秒= 1000000纳秒).这比它看起来更加狡猾.
我建议不要在没有实际测试代码或准备好工作代码示例的情况下发布答案:)
我在SWT/JFace中寻找一个支持自动完成/提前输入的组合(查看器),即用户可以输入几个字符,下拉列表应该显示所有匹配的元素.
有人可以告诉我一个可靠的方法来获取Java资源的最后修改时间吗?资源可以是JAR中的文件或条目.
我有一个RMI服务器和一个桌面RMI客户端.当我重新启动服务器时,我在客户端遇到错误.是否可以在不重新启动客户端的情况下重新启动RMI连接?
[编辑]这是堆栈跟踪:
java.rmi.ConnectException: Connection refused to host: xxx.xxx.xxx.xxx; nested exception is:
java.net.ConnectException: Connection refused: connect
at ...user code...
Caused by: java.rmi.ConnectException: Connection refused to host: xxx.xxx.xxx.xxx; nested exception is:
java.net.ConnectException: Connection refused: connect
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:574)
at sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:185)
at sun.rmi.transport.tcp.TCPChannel.newConnection(TCPChannel.java:171)
at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:94)
at java.rmi.server.RemoteObjectInvocationHandler.invokeRemoteMethod(RemoteObjectInvocationHandler.java:179)
at java.rmi.server.RemoteObjectInvocationHandler.invoke(RemoteObjectInvocationHandler.java:132)
at $Proxy0.search(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:592)
at org.springframework.remoting.rmi.RmiClientInterceptorUtils.invokeRemoteMethod(RmiClientInterceptorUtils.java:108)
at org.springframework.remoting.rmi.RmiClientInterceptor.doInvoke(RmiClientInterceptor.java:362)
at org.springframework.remoting.rmi.RmiClientInterceptor.invoke(RmiClientInterceptor.java:258)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
at $Proxy1.search(Unknown Source)
... 3 more
Caused by: java.net.ConnectException: Connection refused: connect
at …Run Code Online (Sandbox Code Playgroud) SWT附带一个基础JAR和每个平台一个特定的JAR(Windows,Linux/32位,Linux/64位,Mac,AIX,...).如何创建可在运行时选择正确平台JAR的可执行JAR?
[编辑]我想在一个子目录中提供所有平台JAR,main()然后修改类加载器.有没有人试过这个?
我必须script在HTML页面的元素内部转义哪些JavaScript代码?是否<>&足够或太多?
[编辑]这与此错误有关:http://code.google.com/p/rendersnake/issues/detail? id = 15#c6评论#6
当我尝试运行Hibernate时,我在控制台中收到以下消息.
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Run Code Online (Sandbox Code Playgroud)
但是冬眠很好.我的项目有什么问题吗?我使用Eclipse(Helios),Hibernate 3.6.8.我使用这些jar文件:antlr-2.7.6,commons-collections-3.1,dom4j-1.6.1,hibernate3,hibernate-jpa-2.0-api-1.0.1.Final,javassist-3.12.0.GA,jta- 1.1,slf4j-api-1.6.1
我正在编写自己的范围(即实现的类org.springframework.beans.factory.config.Scope),我需要注入一些bean.我怎么做?
背景:Spring必须首先创建所有范围bean,以便我可以定义哪些bean进入范围.但是,首先需要构建范围的bean呢?
当我构建我的项目时,我收到以下警告:
[INFO] ------------------------------------------------------------------------
[INFO] Building XXX
[INFO] ------------------------------------------------------------------------
[WARNING] The POM for org.eclipse.update:org.eclipse.update.configurator:jar:3.2.0 is missing, no dependency information available
[WARNING] The POM for org.eclipse.emf:org.eclipse.emf.ecore:jar:2.3.2 is missing, no dependency information available
[WARNING] The POM for com.ibm.icu:com.ibm.icu:jar:3.4.4 is missing, no dependency information available
Run Code Online (Sandbox Code Playgroud)
在我的构建中,我覆盖了这些依赖项的版本,并且构建本身也成功了.
修复警告的最快方法是什么?
编辑:找到包含这些版本的POM的最快方法是什么?
注意:我的本地仓库中有7000个POM.
当我运行此代码时:
System.out.println( "XXX date=" + new Date( 1311781583373L ) );
Run Code Online (Sandbox Code Playgroud)
我在Eclipse的JUnit运行器中得到了这个结果:
XXX date=Wed Jul 27 16:46:23 GMT+01:00 2011
Run Code Online (Sandbox Code Playgroud)
这从命令行导致Maven:
XXX date=Wed Jul 27 17:46:23 CEST 2011
Run Code Online (Sandbox Code Playgroud)
如你所见,时间不同.
(相同的计算机,相同的Java版本,可能相差30秒).为什么?
[编辑]此外,时区也不同.为什么Java CEST从Maven GMT+01:00启动时以及从Eclipse启动时使用?
或者换一种说法:我如何强迫Java使用?
java ×6
swt ×2
autocomplete ×1
connection ×1
date ×1
dependencies ×1
escaping ×1
executable ×1
hibernate ×1
html ×1
javascript ×1
jface ×1
maven ×1
pom.xml ×1
portability ×1
resources ×1
restart ×1
rmi ×1
scope ×1
slf4j ×1
spring ×1
timestamp ×1
timezone ×1
type-ahead ×1
warnings ×1