Se nelle nostre applicazioni Java abbiamo bisogno di interrogare l'Internet Time Service di un Time Server, possiamo utilizzare il Network Time Protocol (NTP), mediante la libreria open source Apache Commons Net.
Vediamone un esempio di utilizzo:
package test;
import java.net.InetAddress;
import java.util.Date;
import org.apache.commons.net.ntp.NTPUDPClient;
import org.apache.commons.net.ntp.TimeInfo;
public class TimeLookup {
// List of time servers: http://tf.nist.gov/service/time-servers.html
// Do not query time server more than once every 4 seconds
public static final String TIME_SERVER = "time-a.nist.gov";
public static void main(String[] args) throws Exception {
NTPUDPClient timeClient = new NTPUDPClient();
InetAddress inetAddress = InetAddress.getByName(TIME_SERVER);
TimeInfo timeInfo = timeClient.getTime(inetAddress);
long returnTime = timeInfo.getReturnTime();
Date time = new Date(returnTime);
System.out.println("Time from " + TIME_SERVER + ": " + time);
}
}
Il Covid torna a minacciare la Calabria. Salgono casi e ricoveri. Il tasso sfiora il 32%
-
CATANZARO In Calabria, ad oggi, il totale dei tamponi eseguiti sono stati
325.5964 (+6.879). Le persone risultate positive al Coronavirus sono
420.825 (+2....
2 ore fa
Nessun commento:
Posta un commento