我正在尝试做一些看似很简单的事情,但是我一生无法使它正常工作。
我想将某些字符串解析为LocalTime,然后以所需的格式打印它们。我想要的是:
HH:mm:ss(13:00:00打印为13:00:00)。13:45:20并且13:45:20.000两个都打印为13:45:20)13:45:20.01打印为13:45:20.010)根据以下文档,似乎可以在DateTimeFormatter中使用可选选项optionalStart:
All elements in the optional section are treated as optional.
During formatting, the section is only output if data is available in the
{@code TemporalAccessor} for all the elements in the section.
During parsing, the whole section may be missing from the parsed string.
Run Code Online (Sandbox Code Playgroud)
但是,强制将Millis保留为小数点后3位似乎绕过了可选方面,即.000在millis == 0时被打印:
final DateTimeFormatter formatter = …Run Code Online (Sandbox Code Playgroud) 我知道多Q&作为[的1,2 ]是紧密联系在这个问题上,我一直试图实现他们的解决方案,但事实证明,我需要使用.在我的连接中似乎给我带来了麻烦.
这就是我要的:
#include <stdio.h>
#define PROPERTY .value1
#define MAKE_PROP(var) var##PROPERTY
typedef struct {
int value1;
int value2;
} Node;
int main(void) {
Node node;
node.value1 = 1;
node.value2 = 2;
// MAKE_PROP(node) should evaluate to "node.value1".
printf("%d", MAKE_PROP(node));
return 0;
}
Run Code Online (Sandbox Code Playgroud)
然而它给了我各种各样的错误.如果我尝试[ 2 ]中的PASTER-EVALUATE想法,那么它会告诉我"粘贴"."和"PROPERTY"没有给出有效的预处理令牌".
谁知道如何完成我需要的东西?它必须保持一般,并且我可以使用,var因为这是我想在不同的变量名称上多次调用的东西.