我有这段代码正在生成一个时间戳,然后解析。
DateTimeFormatter formatter =
DateTimeFormatter
.ofPattern("yyyyMMdd kk:HH:ss.SSSZ")
.withLocale(Locale.getDefault())
.withZone(ZoneId.systemDefault());
Instant now = Instant.now();
String formatted = formatter.format(now);
Instant parsed = formatter.parse(formatted, Instant::from);
Run Code Online (Sandbox Code Playgroud)
运行时,最后一行会产生异常:
java.time.format.DateTimeParseException: Text '20180123 12:12:45.648-0500' could not be parsed: Unable to obtain Instant from TemporalAccessor: {SecondOfMinute=45, NanoOfSecond=648000000, OffsetSeconds=-18000, MilliOfSecond=648, MicroOfSecond=648000, HourOfDay=12},ISO,America/New_York resolved to 2018-01-23 of type java.time.format.Parsed
Caused by: java.time.DateTimeException: Unable to obtain Instant from TemporalAccessor: {SecondOfMinute=45, NanoOfSecond=648000000, OffsetSeconds=-18000, MilliOfSecond=648, MicroOfSecond=648000, HourOfDay=12},ISO,America/New_York resolved to 2018-01-23 of type java.time.format.Parsed
Caused by: java.time.temporal.UnsupportedTemporalTypeException: **Unsupported field: InstantSeconds**
Run Code Online (Sandbox Code Playgroud)
我用DateTimeFormatter.ISO_INSTANT替换了格式化程序,它可以正常工作。产生的实际数据几乎相同。什么是断开连接?
ISO_INSTANT: …Run Code Online (Sandbox Code Playgroud) 我需要处理一个列表,并为每个项目调用目标对象上的不同方法.看起来很优雅,我可以创建一个方法引用列表来执行此操作,因此对于列表中的每个索引,我可以调用与其对应的适当方法引用.
private final static List<Consumer<String>> METHODS = (List<Consumer<String>>) Arrays.asList(
TargetClass::setValue1,
TargetClass::setValue2,
TargetClass::setValue3,
TargetClass::setValue4,
TargetClass::setValue5);
Run Code Online (Sandbox Code Playgroud)
但是,Eclipse正在使用错误标记这些错误.此表达式的目标类型必须是功能接口.现在,TargetClass这里是一个普通的类,而不是一个接口...这是否意味着没有办法完成我在这里尝试做的事情?
我正在尝试编写一个简单的测试用例来根据消息属性从队列中提取消息,达到 7.5.0.3 QMgr 并使用 7.5.0.3 客户端 jar。
我在网上看到的一切都说我需要在打开队列时指定消息选择器。我没问题,但我只看到两种打开方式:
MQQueueManager.accessQueue(
String queueName,
int openOptions);
MQQueueManager.accessQueue(
String queueName,
int openOptions,
String queueMgr,
String dynamicQueueName,
String altUserId);
Run Code Online (Sandbox Code Playgroud)
这些都不允许我指定消息选择器。我从命令行批处理应用程序运行它,而不是在应用程序服务器中,因此无法使用 JMS 选择器。
以下是有关选择器的 IBM 文档:WebSphere MQ 消息选择器,其中显示选择必须作为 MQOPEN 调用的一部分发生。