user1726619 user1726619 - 2 months ago 16
Android Question

How to get current time from internet in android

I am making an app in which I want to get the current time from internet.

I know how to get the time from the device using

, and even after searching a lot, I did not get any clue about how to get it from internet.


You can get time from internet time servers using the below program



public final class GetTime {

    public static final void main(String[] args) {
        try {
            TimeTCPClient client = new TimeTCPClient();
            try {
                // Set timeout of 60 seconds
                // Connecting to time server
                // Other time servers can be found at :
                // Make sure that your program NEVER queries a server more frequently than once every 4 seconds
            } finally {
        } catch (IOException e) {

1.You would need Apache Commons Net library for this to work. Download the library and add to your project build path.

(Or you can also use the trimmed Apache Commons Net Library here : This is enough to get time from internet )

2.Run the program. You will get the time printed on your console.