Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get actual DateTime of a device in Offline Mode

I am developing an android application. I need to solve the below mentioned issue in my application:

1) The application can work in online as well as offline. The app has a feature to create and save the NOTES inside the application. Also, When the app gets internet connection, I need to send the NOTES to backend server. I have a field called 'DATECREATED' in each NOTE (the datetime where the actual NOTE was created)

ISSUE: If the User has set the DateTime wrongly in the device, My application sends the incorrect DATETIME to server. I am wondering how could I solve the issue? Any Ideas would be appreciable.

like image 754
Anees Deen Avatar asked Sep 29 '22 01:09

Anees Deen


1 Answers

When you eventually post to your server, just add that specific time as well. new Date().getTime() will give you a value that you can use to compare with the datetime of your server. If it's for example 2 hours later, then just set the time of the post 2 hours back.

So send both the time when the post was submitted by the user and the time when it was actually sent.

like image 153
dumazy Avatar answered Oct 03 '22 08:10

dumazy