"timestamp_utc": "????-??-??T??:??:??+??:??"
Run Code Online (Sandbox Code Playgroud)
是JSON中的属性.我该如何解析这个日期?我尝试了下面这段代码.
try
{
return new DateTime(dateStr, DateTimeZone.UTC);
}
catch (IllegalArgumentException e)
{
java.util.Locale locale = new java.util.Locale( "ar", "SA" );
DateTimeFormatter formatter = ISODateTimeFormat.dateTime().withLocale( locale );
return formatter.parseDateTime( dateStr );
}
Run Code Online (Sandbox Code Playgroud)
2015-05-11T11:31:47工作得很好.然而,
????-??-??T??:??:??+??:??抛出一个IllegalArgumentException.尝试使用其他语言环境/格式解析日期.没运气.
Locale list[] = DateFormat.getAvailableLocales();
for (Locale aLocale : list) {
try{
DateTimeFormatter formatter = DateTimeFormat.forPattern( "yyyy-MM-dd'T'HH:mm:ssZ" ).withLocale(aLocale);
System.out.println(formatter.parseDateTime( dateStr ));
}
catch(Exception e){
System.out.println("locale " + aLocale.toString() + " error");
}
}
Run Code Online (Sandbox Code Playgroud)
请帮帮我.
我正在努力修复其中一个项目中的集成测试.目前,所有集成测试类都扩展了JerseyTest类.通过JerseyTest类,我意识到它使用Junit的Before和After注释为每个测试方法启动和停止容器.
为什么这有必要?如果我们提起容器一次,运行测试并在结束时将其关闭,这还不够吗?
我们也使用Spring,上下文初始化需要时间.
在Junit4之前,我们通过使用布尔标志手动处理它来解决这个限制.
@Before
public void setup() {
if(!containerStarted) {
// start
containerStarted = true;
}
// else do nothing
}
Run Code Online (Sandbox Code Playgroud) 我有一个clojure函数,它调用另一个函数来更新数据库.
(^{PUT true
Path "/{id}"
Produces ["application/json"]
Consumes ["application/json"]
ApiOperation {:value "Update" :notes ""}}
updateFeedback [this
^{PathParam "id"} id
body]
(require 'com.xx.x.xx.xx.xx-response)
(let [doc (json/read-json body)]
(if-let [valid-doc (validate doc)]
(try+
(->>
(assoc valid-doc :modificationDate (Utilities/getCurrentDate))
(couch/update-document dbs/xx-db)
(core/ok-response))
(catch java.io.IOException ex
(log/error "line num 197"))
(catch java.lang.Exception ex
(log/error "line num 200"))))))
Run Code Online (Sandbox Code Playgroud)
update-document函数抛出异常.我想把它扔回调用者 - 在这种情况下updateFeedback,以便catch块中的内容被执行.出于某种原因,clojure会记录异常,并且调用者中的catch块永远不会执行.
验证我是否在try catch块中的update-document函数中包装了代码.catch块被执行了.
如何在函数中添加throws子句?
更新:我已更新该功能.对语法问题表示歉意.我已经更新了我们正在使用的代码.我不熟悉clojure.这是我们继承的代码,我们被要求修复错误.任何指针都会非常有用.