Java: Get Local Time Of Website’s Server

If you want to get the date and time of a website’s server and if it is not displayed within the website, you can do so by getting the headers that are returned. In Java, you would use the URL and HttpURLConnection classes to meet this objective. You can then loop through the HttpURLConnection object’s headers and see what the header name for the date and time is. One site that I accessed had the header name “Date” so you may want to try this out. If you know the header name you do not have to loop through each header but just call the getHeaderField(String name) method of the HttpURLConnection object.

See sample code below

Related Posts Plugin for WordPress, Blogger...

Leave a Reply

Your email address will not be published. Required fields are marked *