-1

Good evening,

I'm trying to synchronize data between a server and an android device, the problem is I need to get the date and time that are the same as date and time in the server.

However using Simpledateformat and date will not work, since sometimes the device will be ahead of time for about 1-2 minutes which will cause a problem.

After searching I found this however I prefer another solution since I need my application to work even if there is no internet.

The sequence of actions that will be taken is as follows:

1- Every request will use the same date and time as the server. 2- Store that request on the local database. 3- Convert the date and time of the request to local time in order to display it on the phone.

Thanks for your help.

Community
  • 1
  • 1
  • I didn't quite understand. In step 1, who requests whom? Is the request going from phone to server or server to phone? – EdmDroid Aug 29 '16 at 13:50
  • If the user has no internet then the changes are stored in the database until he has internet then the server will be updated. All I want is to store the local changes in the server time not the device time. – J. Doe 2 Aug 29 '16 at 14:07
  • Is it possible to just store the changes without the timestamp and then when you contact the server, let the server put its own timestamp? That way you can store changes on the server using the server's timestamp – EdmDroid Aug 29 '16 at 14:16

1 Answers1

-1

If you wants your app to work without internet, then the device time and date is only way.

In your flow if "1- Every request will use the same date and time as the server. " is the server request then you can get time from server in the response.

  • Thanks for your comment, even if I get the time, what would I do with it ? what I want is to store the local changes in the same time as the server, so if the server's time is 1 PM and I made a local change in a device whose local time is 1:02 PM then the change should be 1 PM. – J. Doe 2 Aug 29 '16 at 14:06