简体   繁体   English

是否可以确定发出 api 请求的机器的本地时间?

[英]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.

相关问题 如何确定传入连接来自本地计算机 - How to determine an incoming connection is from local machine 从数据库时间转换为本地计算机时间时,时间不正确 - Incorrect time when converting from DB time to local machine time 以编程方式知道在Tomcat中从哪个连接器发出的请求 - programmatically know from which connector the request made in tomcat 将响应从队列返回到发出请求的同一服务器 - Getting the response back from the queue to the same server which made the request 是否可以在包含Java 1.6的本地计算机上执行Java 1.7编译的代码文件 - is it possible to execute java 1.7 compiled code file in local machine which contains java 1.6 判断api请求是来自CURL还是POSTMAN? - Determine whether the api request comes from CURL or POSTMAN? 比较Google驱动器上的文件和存储在本地计算机上的文件的上次修改时间 - Compare last modified time of file on google drive and file which is stored on local machine 无法使用 Java API 连接到在本地虚拟机上运行的 ElasticSearch Docker 集群 - Can't connect to ElasticSearch Docker cluster which run on local virtual machine using Java API 如何确定另一台本地计算机是否还活着? - How can I determine if another local machine is alive? 是否可以确定请求JSON中是否存在参数 - Is it possible to determine whether parameters are present in request JSON
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM