5

In m,y android application i would like to use time which do not come from device but a standard time that the user cannot change. Is there any way to do this.

Please share your valuable suggestions.

Thanks in advance:)

Remmyabhavan
  • 1,689
  • 5
  • 36
  • 65

4 Answers4

6

You can use NTP for fetching the time from any of the public NTP servers. You can read the example SNTP client code for java here.

bhups
  • 14,345
  • 8
  • 49
  • 57
0

I'm unclear on the question here. The time on the phone in almost all (maybe all?) cases will be from the network, which will be the official time. If you need it in a different time zone that shouldn't be a difficult conversion.

Kevin Coppock
  • 133,643
  • 45
  • 263
  • 274
  • I need the same timezone but the issue is it shouldnot be device time because device time can vary as the user can change the device time.I need this time to validate the subscription charges. – Remmyabhavan Sep 01 '10 at 05:41
  • 1
    If you're using it for some sort of validation, you're better off sending a request to a server that you control and storing the subscription details on that. Putting billing information in the APK itself is just opening yourself up to people trying to circumvent your system. – Drew Sep 03 '10 at 07:36
0

If you don't mind the overhead, you could make a request to a time server for the official time. I'm sure there's one out there somewhere that accepts JSON or webservice requests.

Drew
  • 2,269
  • 21
  • 16
0

This will give you the current time:

System.currentTimeMillis();
Sean Vieira
  • 155,703
  • 32
  • 311
  • 293
Rakesh Gondaliya
  • 1,050
  • 3
  • 25
  • 42