title: Android Time Synchronization in UTC
body: <p>I have an application that relies heavily on current timestamps. Currently, when user submits a request, I get the current timestamp in UTC using <code>System.currentTimeMillis()</code>. While this works fine, it becomes a problem when the user starts manipulating their <code>Date/Time</code> on their device and would result as inaccurate timestamps.</p>
  
  <p>Why do it on the client then? Why not just handle it on the server? Well, my application needs to work offline. All my requests get pushed into a <code>jobQueue</code> when connectivity to the internet is unavailable. In these cases, I must have the original time wherein the user did the action so if I submit a request at <code>4:02pm</code>, but due to network problems, server will only receive it around <code>7:30pm</code>, server MUST know that I sent the request at <code>4:02pm</code>.</p>
  
  <p><strong>Now what options have I considered?</strong></p>
  
  <ol>
  <li>Upon user login, I sync the device time with the server time and store that time locally. If any user manipulation occurs while the user is logged in, I'll have a <code>BroadcastReceiver</code> listening in onto any intents of <code>Date/Time</code> manipulation, then store the offset so that whenever a user submits a request, I will calculate the synced time with the offset to ensure the timestamp is accurate.</li>
  <li>Have a server sync api done in the backend and set up a service within my application to continuously sync up with the server time and look for any drift while also listening in onto any user manipulation.</li>
  <li>Use push notifications and listen downstream for time synchronization adjustments while also listening onto any user manipulation.</li>
  <li>I could also make use of the <code>NTP</code> servers to synchronize time with my device.</li>
  </ol>
  
  <p>I'm not entirely sure which would be the most optimal (assuming I have listed down all the possible solutions). If there are other solutions I haven't thought of, please let me know.</p>
  
  <p>P.S. If I happen to use the <code>BroadcastReceiver</code> to listen onto any datetime manipulation on the device, how would I even calculate the offset in that?</p>