1
import java.text.SimpleDateFormat;
import java.util.Calendar;

public class currentTime {

    public static void main(String[] args) {
        Calendar cal = Calendar.getInstance();
        SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
        System.out.println( sdf.format(cal.getTime()) );
    }

}

If I change my system date it will automatically change TO same time.... so... I need to show original internet server time without system time...... anyone pls ans this.......

fabian
  • 80,457
  • 12
  • 86
  • 114

1 Answers1

1
    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 {

    public static void main() throws Exception {
                String TIME_SERVER = "time-a.nist.gov";   
        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);
    }
}

Try this code.. Its working

Naren P
  • 214
  • 3
  • 14