Here's some code to fetch the date in HTTP format (usually UTC timezone) from a web server of your choice.
Of course, if you have no control over the physical hardware and OS, nothing can guarantee you will be able to talk to the actual web server you ask for... but anyway.
package some.package;
import java.io.IOException;
import java.net.URL;
import java.net.URLConnection;
import java.util.List;
import java.util.Map;
public class Test {
private static String getServerHttpDate(String serverUrl) throws IOException {
URL url = new URL(serverUrl);
URLConnection connection = url.openConnection();
Map> httpHeaders = connection.getHeaderFields();
for (Map.Entry> entry : httpHeaders.entrySet()) {
String headerName = entry.getKey();
if (headerName != null && headerName.equalsIgnoreCase("date")) {
return entry.getValue().get(0);
}
}
return null;
}
public static void main(String[] args) throws IOException {
String serverUrl = args.length > 0 ? args[0] : "https://google.com";
System.out.println(getServerHttpDate(serverUrl));
}
}