CouchDB:在CouchApp中使用http请求获取服务器时间

问题描述

|| 我需要在CouchApp中获取用户在线”统计信息的服务器时间。我使用jquery.couch.js并希望有一个网址,例如/ db / _design / app / time-给我一个时间戳。 我怎么知道的?     

解决方法

show函数可以做到这一点:
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
           };
}
服务器还包括您可能要使用的“ 1”头。
$ 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\"}
    

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...