2

can Anybody please give me exact solution of this problem programmaticaly i.e. when i change the device time it's taking device time but i want that it should take actual time from internet. i am using this code...

  SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
        String date = dateFormat.format(new Date(System.currentTimeMillis()));

i tried this also

final Calendar c = Calendar.getInstance();
    year = c.get(Calendar.YEAR);
    month = c.get(Calendar.MONTH);
    day = c.get(Calendar.DAY_OF_MONTH);
    hour = c.get(Calendar.HOUR_OF_DAY);
    minute = c.get(Calendar.MINUTE);

    int myfrmt =(c.get(Calendar.YEAR) + c.get(Calendar.MONTH) + c.get(Calendar.DAY_OF_MONTH) + c.get(Calendar.HOUR_OF_DAY)+ c.get(Calendar.MINUTE));
    String satyam=Integer.toString(myfrmt);`

but in both the case i got device time .... not real time

Blackbelt
  • 156,034
  • 29
  • 297
  • 305
user3164420
  • 41
  • 1
  • 2

3 Answers3

2

Have you tried this:

LocationManager locMan = (LocationManager) activity.getSystemService(activity.LOCATION_SERVICE);
long time = locMan.getLastKnownLocation(LocationManager.NETWORK_PROVIDER).getTime();

This will provide the time through your network provider.

demongolem
  • 9,474
  • 36
  • 90
  • 105
Chomu
  • 214
  • 1
  • 10
0

Just have a look at this. The thread has multiple answers which are worth checking out. I would recommend the "correct" answer although you have to include a library for this. If you use the first answer please also notice the comments concerning server choice.

Hope it helps.

Community
  • 1
  • 1
Robin Ellerkmann
  • 2,083
  • 4
  • 29
  • 34
0

I would suggest making a simple AJAX call to

http://www.timeapi.org/utc/now

A handy web service which returns current GMT time that you could manipulate.

Starscream1984
  • 3,072
  • 1
  • 19
  • 27