【发布时间】:2017-03-29 20:30:31
【问题描述】:
在碧玉报告中我正在尝试以下内容
new SimpleDateFormat("dd.MM.yyyy HH:mm").setTimeZone(TimeZone.getTimeZone("UTC")).format( new Date(1483337940000L));
在文本字段表达式中。
但我得到了错误
无法在原始类型 void 上调用格式(日期)
是不是和java下面的代码一样?
1483337940000L is 02.01.2107 07:19
SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy HH:mm");
sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
String test = sdf.format(new Date(1483337940000L)); // Here I am getting 06:19
String test2 = new SimpleDateFormat("dd.MM.yyyy HH:mm").setTimeZone(TimeZone.getTimeZone("UTC")).format( new Date(1483337940000L)); // Here I am getting the error Cannot invoke format(Date) on the primitive type void
【问题讨论】:
-
setTimeZone 不返回值。这是一个无效的方法
-
成语
obj.operation1().operation2().operation3()仅在每个操作都定义为返回调用它的对象时才有效。这不是该操作的定义方式,因此您不能使用这种“链式命令”习语。 -
我想这里不会发生其他事情;所以请考虑在某个时候接受 ;-)
标签: java