Gemalto is now part of the Thales Group, find out more.

You are here

Thales IoT Developer Community

NTP - How to use net time protocol on J2ME

Showcase, February 18, 2015 - 10:43am, 4893 views

Attached an example how to get the time form a NTP server.

Find source attached, comments are included.

If you want to run the code please modify the APN in regards to the used SIM/MNO

 sntpclient.setApn("apn of your mobile operator");   (  - line 22)

If needed setters for username and password are available in the object as well.

Log file of the debug session:

Registering ip address "" of remote debugging device...

Waiting for debug device registration of "IMP_NG_EHS5_REMOTE"...

Passing control to external device emulator...

Installing suite from:

Connection state: CONNECTING

Connection state: UP

HTTP response: Found


NTP request sent, waiting for response...

NTP server:

Leap indicator: 0

Version: 3

****: 4

Stratum: 3

Poll: 3

Precision: -22

Root delay: 5.8746337890625 ms

Root dispersion: 66.4520263671875 ms

Reference identifier:

Reference timestamp: Wed Feb 18 07:35:48 GMT+00:00 2015, fraction 0.8753509521484375

Originate timestamp: Thu Jan 08 21:17:09 GMT+00:00 2004, fraction 0.694000244140625

Receive timestamp:   Wed Feb 18 08:08:37 GMT+00:00 2015, fraction 0.010018348693847656

Transmit timestamp:  Wed Feb 18 08:08:37 GMT+00:00 2015, fraction 0.010127067565917969

Dest. timestamp:     Thu Jan 08 21:17:10 GMT+00:00 2004, fraction 0.21899986267089844

Round-trip delay: 524.8908996582031 ms

Local clock offset: 3.5065028705357263E11 ms

Local time 3.50650287E8sec late

97402h 51m 27s 

End of debug session. Emulator is closed!

Download File (zip | 37.84 KB)


Thank you for this code.

A little remark: I think it is better not to use additional parameters (dns, bearer,access_point) in the string "datagram://" + serverName + ":123"....

because these parameters are not described for UDPDatagramConnection interface.

Using these additional parameters caused haning my midlet (EHS5 module)..



Markus's picture