[英]is it possible to determine local time of the machine from which an api request is made?
I want to know the current time of the machine from which a request is made to my api written in java.我想知道用 java 向我的 api 发出请求的机器的当前时间。 Is it possible to do that using some function of HttpServletRequest?
是否可以使用一些 HttpServletRequest 的 function 来做到这一点?
No. Not using the java api request as requests are created by users.But if you have a UI application sending requests to java application that application can get the client machine's date & your Ui code can send this date in request.没有。不使用 java api 请求,因为请求是由用户创建的。但是,如果您有一个 UI 应用程序向 java 应用程序发送请求,那么 Ui 应用程序可以在请求中获取此日期和客户端机器的日期和日期。
var currentDate = new Date();
var currentDate = new Date();
you can format and send the date now to server.您现在可以格式化并将日期发送到服务器。
// from this link :
//https://www.tutorialspoint.com/servlets/servlets-handling-date.htm
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// Set response content type
response.setContentType("text/html");
PrintWriter out = response.getWriter();
String title = "Display Current Date & Time";
Date date = new Date();
String docType = "<!doctype html public \"-//w3c//dtd html 4.0 " + "transitional//en\">\n";
out.println(docType +
"<html>\n" +
"<head><title>" + title + "</title></head>\n" +
"<body bgcolor = \"#f0f0f0\">\n" +
"<h1 align = \"center\">" + title + "</h1>\n" +
"<h2 align = \"center\">" + date.toString() + "</h2>\n" +
"</body>
</html>"
);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.