小编Dav*_*ley的帖子

为什么在1971年11月1日之前将一小时添加到java.util.Date的日期?

以下代码似乎演示了java.util.Date中的一个错误,如果本地时钟设置为GMT且DST调整开启且时间早于1971年11月1日,则会添加一小时.我的第一个假设始终是我的弄错了.任何人都可以看到什么是错的(或者这真的是一个Java错误)?1971年11月1日有什么重要意义?

import java.text.SimpleDateFormat;
import java.util.Locale;
import java.util.TimeZone;

class JavaUtilDateBug
{
    private static void demo() throws Exception
    {
        // UK developers usually have the clock on their development machines set
        // to "Europe/London" (i.e. GMT with daylight saving). Set it explicitly 
        // here so readers in other countries can see the problem too.
        TimeZone.setDefault(TimeZone.getTimeZone("Europe/London"));
        Locale.setDefault(Locale.ENGLISH);

        SimpleDateFormat dateFormat = new SimpleDateFormat("EEE MMM dd HH:mm:ss z yyyy");
        String strJan1st1970Expected = "Thu Jan 01 00:00:00 GMT 1970";
        String strJan1st1970Actual = dateFormat.parse(strJan1st1970Expected).toString();
        System.out.println("strJan1st1970Actual: " + …
Run Code Online (Sandbox Code Playgroud)

java datetime

18
推荐指数
3
解决办法
1711
查看次数

Selenium 2 - 可以将findElement(By.xpath)限定为特定元素吗?

我看到的findElement(By.xpath)的所有例子都在搜索整个页面,例如

WebElement td = driver.findElement(By.xpath("//td[3]"));
Run Code Online (Sandbox Code Playgroud)

我想要实现的是:

WebElement tr = ... // find a particular table row (no problem here)
WebElement td = tr.findElement(By.xpath("/td[3]"));  // Doesn't work!
Run Code Online (Sandbox Code Playgroud)

我还尝试了其他变种而没有运气:"td [3]","child :: td [3]"

使用"// td [3]"查找整个页面中的第一个匹配节点,即不限于我的tr.所以看起来就像当你通过xpath找到元素时,你调用findElement()的WebElement一无所获.

是否可以将findElement(By.xpath)范围限定为特定的WebElement?

(我正在使用Chrome,以防万一.)

请注意: By.xpath("// td [3]")只是一个例子.我不是在寻找实现同样目标的替代方法.问题只是试图确定foo.findElement()在与By.xpath选择器一起使用时是否接受foo的任何通知.

selenium selenium-webdriver

13
推荐指数
3
解决办法
1万
查看次数

如何将Pydev项目导入交互式控制台?

新手问题(我刚刚开始使用Python和Pydev):

我用(标准?)src/root子文件夹创建了一个项目"Playground".在那里我创建了example.py.

如何将"示例"模块导入Pydev的交互式控制台?">>>导入示例"给出:"ImportError:没有名为example的模块"

python pydev

8
推荐指数
2
解决办法
4887
查看次数

我可以使用Spring EL的属性占位符吗?

在升级到Spring 3之前,我在applicationContext.xml文件中有这个:

    <bean class="com.northgateis.pole.ws.PolePayloadValidatingInterceptor">
      <property name="validateRequest" value="${validateRequest}" />
      <property name="validateResponse" value="${validateResponse}" />
    </bean>
Run Code Online (Sandbox Code Playgroud)

其中$ {validateRequest)和$ {validateRequest)引用可能在我的属性文件中定义的属性.

在Spring 2中,如果属性文件中没有这些proeprties,则不会调用bean上的setter,因此使用了PolePayloadValidatingInterceptor中的硬编码默认值.

升级到Spring 3之后,行为似乎有所不同:如果属性文件中不存在属性,则会出现以下异常:

SEVERE: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanDefinitionStoreException: Invalid bean definition with name 'annotationMapping' defined in class path resource [com/northgateis/pole/ws/applicationContext-ws.xml]: Could not resolve placeholder 'validateRequest'
 at org.springframework.beans.factory.config.PropertyPlaceholderConfigurer.processProperties(PropertyPlaceholderConfigurer.java:272)
 at org.springframework.beans.factory.config.PropertyResourceConfigurer.postProcessBeanFactory(PropertyResourceConfigurer.java:75)
 at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:640)
 at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:615)
 at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:405)
 at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:272)
Run Code Online (Sandbox Code Playgroud)

我尝试过使用Spring EL,但以下似乎不起作用:

    <bean class="com.northgateis.pole.ws.PolePayloadValidatingInterceptor">
      <property name="validateRequest" value="${validateRequest?:true}" />
      <property name="validateResponse" value="${validateResponse?:false}" />
    </bean>
Run Code Online (Sandbox Code Playgroud)

始终使用Elvis运算符后的值,即使在proeprties文件中定义属性时也是如此.有趣的是语法被接受了.

有什么建议?

spring spring-el

4
推荐指数
1
解决办法
7715
查看次数

为什么不在启用夏令时的情况下运行服务器端应用程序?

我已经实现了一个服务器端应用程序,它记录了创建和更新记录时的时间戳.该应用程序假定服务器时钟没有启用夏令时,(a)因为我读过这是最佳做法和(b)因为我认为处理发生的歧义会很棘手(如果不是不可能的话),例如,当时钟在10月回归一个小时.

为安全起见,如果应用程序在启动时检测到DST已启用,则会记录错误并终止应用程序.即使应用服务器时钟启用了DST,我也会被内部利益相关者请求使应用程序正常工作.

我觉得尝试这样做是个愚蠢的事情,但我需要说服管理层.只是因为它使实现变得更加棘手,或者它是否存在根本上的缺陷,以至于这样的应用程序(记录时间戳)在一年中的任何时候都无法正确运行100%?在没有启用DST的情况下运行这样的应用程序的最佳理由是什么?

我想出的最好的是:

启用夏令时后,每年有两次不连续时间.请考虑以下情形,其中服务器在英国运行,时钟设置为启用夏令时的本地时间:
  • 2009年10月25日凌晨2点,时钟可以追溯到凌晨1点到凌晨1点.
  • 记录在凌晨1点30分创建
  • 应用程序(必须以UTC格式存储时间戳)无法判断这是在时钟返回之前或之后的1.30am,因此无法确定是否在UTC调整中包含额外的小时.
  • 这是真的?实际上是否可以确定(在Java Web应用程序中)10月25日凌晨1点30分发生的事件是在时钟调整之前还是之后?

    避免夏令时的任何更好的理由?

    更新

    需要明确的是,应用程序必须时间存储为UTC.问题是为什么在尝试这样做时,在服务器计算机上启用DST是一个坏主意.

    java server-side application-server

    3
    推荐指数
    2
    解决办法
    399
    查看次数