In a Servlet, I’ll like to obtain the datetime when a request is made.
I don’t want to use Java’s Date Class because it could not provide the accurate time.
Any help?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You have three choices:
Use client’s computer time. This will require the client to send his or her system time explicitly in the request parameters or in a custom header. Not to mention arbitrary computer in the Internet might have much more inaccurate time.
Use external time servers to fetch current time.
…or just trust your server, if it uses ntp, you are on the safe side.