Time CouchDB:通过CouchApp中的http请求获取服务器时间

Time CouchDB:通过CouchApp中的http请求获取服务器时间,time,couchdb,couchapp,gettime,Time,Couchdb,Couchapp,Gettime,我需要我的CouchApp中“用户在线”统计的服务器时间。我使用jquery.coach.js,希望有一个url,例如/db/_design/app/time,这会给我一个时间戳。 如何实现这一点?显示功能可以做到: function(doc, req) { // _design/myapp/_show/now // First version possibly incompatible with some spidermonkey versions. //var no

我需要我的CouchApp中“用户在线”统计的服务器时间。我使用jquery.coach.js,希望有一个url,例如/db/_design/app/time,这会给我一个时间戳。
如何实现这一点?

显示功能可以做到:

function(doc, req) {
    // _design/myapp/_show/now

    // First version possibly incompatible with some spidermonkey versions.
    //var now = new Date();
    var now = new Date().getTime();
    var output = JSON.parse(JSON.stringify(now)) + "\n";

    return { code: 200
           , headers: { "Content-Type": "text/plain"
                      }
           , body:output
           };
}
服务器还包括您可能要使用的
Date

$ curl -D- http://localhost:5984
HTTP/1.1 200 OK
Server: CouchDB/1.1.0 (Erlang OTP/R14B)
Date: Fri, 27 May 2011 00:28:31 GMT
Content-Type: text/plain;charset=utf-8
Content-Length: 40
Cache-Control: must-revalidate

{"couchdb":"Welcome","version":"1.1.0"}

show函数返回“[object,object]”,但我将其更改为var now=new Date().getTime();成功了!非常感谢!尽管这是一个很老的问题,但我还是忍不住要发表评论。我使用了上面的显示功能,非常好。但结果是缓存的。这意味着你一次又一次地得到同样的结果。所以要小心。