1

不重复:我打算针对这个问题解决java.lang.IllegalArgumentException在尝试将格式化的日期添加回 aParseObject以进行渲染时抛出的问题。

我有一个日期列表,当我将它们呈现到我的页面时,我想以更易读的格式显示它们。即我想Wed Mar 29 13:32:35 CEST 2017成为Wed Mar 29

for (ParseObject requestObject: requestsArrayList) {
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    Date date = null;
    try {
        date = sdf.parse(sdf.format(requestObject.getDate(ParseConstantsUtil.REQUEST_DATE_REQUESTED)));
        log.info(String.valueOf(date));
    } catch (java.text.ParseException e1) {
        e1.printStackTrace();
    }
    requestObject.add(ParseConstantsUtil.REQUEST_DATE_REQUESTED, date);
}
requestObject.add(ParseConstantsUtil.REQUEST_DATE_REQUESTED, date);

我认为SimpleDateFormat这就足够了,但我不能放弃额外的时间戳信息并将对象添加回我的集合中。我应该怎么办?

例外:

java.lang.IllegalArgumentException: not implemented!
    at org.parse4j.operation.AddOperation.apply(AddOperation.java:26) ~[parse4j-1.5-SNAPSHOT.jar:na]
    at org.parse4j.ParseObject.performOperation(ParseObject.java:375) ~[parse4j-1.5-SNAPSHOT.jar:na]
    at org.parse4j.ParseObject.addAll(ParseObject.java:301) ~[parse4j-1.5-SNAPSHOT.jar:na]
    at org.parse4j.ParseObject.add(ParseObject.java:296) ~[parse4j-1.5-SNAPSHOT.jar:na]
    at com.nnit.automation.controller.IndexController.findRequestsByCurrentUser(IndexController.java:117) ~[classes/:na]
    at com.nnit.automation.controller.IndexController.findRequestsByCurrentUser(IndexController.java:61) ~[classes/:na]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_121]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_121]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_121]
    at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_121]
4

2 回答 2

1
try {
    SimpleDateFormat inputDate = new SimpleDateFormat("EEE MMM HH:mm:ss yyyy", Locale.US);
    SimpleDateFormat outputDate = new SimpleDateFormat("EEE MMM dd", Locale.US);

    String date = outputDate.format(inputDate.parse(input.replace("CEST ","")));


} catch (ParseException e) {
    e.printStackTrace();
}
于 2017-04-07T10:17:11.033 回答
1

我们始终可以将日期转换为所需格式的字符串并添加到 requestObject

样本更新

for (ParseObject requestObject: requestsArrayList) {
SimpleDateFormat sdf2 = new SimpleDateFormat("E MMM dd");
String date = null;
try {
    date = sdf.format(requestObject.getDate(ParseConstantsUtil.REQUEST_DATE_REQUESTED));
    log.info(String.valueOf(date));
} catch (java.text.ParseException e1) {
    e1.printStackTrace();
}
requestObject.add(ParseConstantsUtil.REQUEST_DATE_REQUESTED, date);
}
于 2017-04-07T10:12:19.813 回答