小编Ern*_*dis的帖子

如何将“2021-11-20+01:00”格式的日期字符串解析为 ZonedDateTime - 错误

如何将“2021-11-20+01:00”格式的日期解析为ZonedDateTime?我正在尝试:

String value = "2021-11-20+01:00";
ZonedDateTime zDate = ZonedDateTime.parse(value, DateTimeFormatter.ofPattern("yyyy-MM-ddxxx"));
Run Code Online (Sandbox Code Playgroud)

但出现这个奇怪的错误:

java.time.format.DateTimeParseException:无法解析文本“2021-11-20+01:00”:无法从 TemporalAccessor 获取 ZonedDateTime:{OffsetSeconds=3600},ISO 解析为 java 类型的 2021-11-20。时间.格式.解析

...不支持的字段:InstantSeconds...

有什么建议么?欧洲 VIES VAT ID 检查系统在接收 XML (SOAP) 响应时使用此时间格式: <requestDate>2021-11-20+01:00</requestDate>。同样的错误与OffsetDateTime..

有趣的是,Javadoc 说“三个字母 (x) 输出小时和分钟,带有冒号,例如 '+01:30'”。那么为什么上面的模式不起作用呢?

也尝试过这个 - 同样的错误:

ZonedDateTime zDate = ZonedDateTime.parse(value, DateTimeFormatter.ISO_OFFSET_DATE);
Run Code Online (Sandbox Code Playgroud)

完整的错误日志:

Exception in thread "main" java.time.format.DateTimeParseException: Text '2021-11-20 +01:00' could not be parsed: Unable to obtain OffsetDateTime from TemporalAccessor: {OffsetSeconds=3600},ISO resolved to 2021-11-20 of type java.time.format.Parsed
    at java.base/java.time.format.DateTimeFormatter.createError(DateTimeFormatter.java:2017)
    at java.base/java.time.format.DateTimeFormatter.parse(DateTimeFormatter.java:1952)
    at …
Run Code Online (Sandbox Code Playgroud)

java parsing localdatetime datetimeformatter

2
推荐指数
1
解决办法
1356
查看次数

如何知道何时将JComponent添加到其父项?

首先,创建JComponent实例jComponent。然后像一样将其添加到其父项中parent.add(jComponent);。现在,我想在jComponent课堂上知道它已添加到它的父项中。有可能这样做吗?

目标是jComponent在已将其添加到父项时设置父项,例如:

Container window = getParent();
        while (!(window instanceof JWindow)) {
            window = window.getParent();
        }
JWindow parent = (JWindow) window;
Run Code Online (Sandbox Code Playgroud)

java swing jcomponent

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

在循环中调用Thread.sleep - 在重新绘制组件时使用延迟的正确方法是什么?

我创建了循环,定期重新绘制组件:

public class A extends Thread {

  private Component component;
  private float scaleFactors[];
  private RescaleOp op;

  public A (Component component){
  this.component = component;
  }

  public void run(){

    float i = 0.05f;
    while (true) {

        scaleFactors = new float[]{1f, 1f, 1f, i};
        op = new RescaleOp(scaleFactors, offsets, null);

        try {
            Thread.sleep(timeout);
        } catch (InterruptedException ex) {
            //Logger.getLogger(...)
        }
        component.repaint();
        i += step;
      }

    }

}
Run Code Online (Sandbox Code Playgroud)

但在这种情况下,我收到消息(NetBeans 7.3.1):

Thread.sleep在循环中调用

也许在这种情况下有更好的解决方案?

java swing

0
推荐指数
1
解决办法
1882
查看次数

JTextField和F10键 - 如何删除键绑定?

我正在尝试删除F10按钮键绑定JTextField,但下面没有任何工作:

getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_F10, KeyEvent.KEY_PRESSED), "none");
getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_F10, KeyEvent.KEY_TYPED), "none");
getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_F10, KeyEvent.KEY_RELEASED), "none");
Run Code Online (Sandbox Code Playgroud)

实际上,我想控制弹出菜单 - 显示/隐藏,但F10不能正常工作 - 它正在执行一些其他操作.如果我切换到例如F11,一切正常.

据我所知 - Shift+ F10在各种平台上显示弹出窗口.

java swing keystroke

0
推荐指数
1
解决办法
1276
查看次数

如何将Array连接到String(Java)?

我们假设有一个数组:

String[] myArray = new String[]{"slim cat", "fat cat", "extremely fat cat"};
Run Code Online (Sandbox Code Playgroud)

现在我想将这个数组转换为带有标记"&"的String,其值为:

苗条的猫和肥猫和极其肥胖的猫

如何在不使用for循环的情况下实现此目的?我的意思是最简单的解决方案,就像我们过去一样someString.split();

java arrays

0
推荐指数
1
解决办法
269
查看次数