Gson dateformat to serialize/deserialize unix-timestamps
<p>I am using Gson to serialize/deserialize my pojos and currently looking for a clean way to tell Gson to parse/output date attributes as unix-timestamps.
Here's my attempt:</p>
<pre><code>Gson gson = new GsonBuilder().setDateFormat(&quot;U&quot;).create();
</code></pre>
<p>Comming from PHP where &quot;U&quot; is the dateformat used to serialize/deserialize date as unix-timestamps, when running my attempt code, I am a <code>RuntimeException</code>:</p>
<blockquote>
<p>Unknown pattern character 'U'</p>
</blockquote>
<p>I am assuming that Gson uses <code>SimpleDateformat</code> under the hood which doesn't define the letter &quot;U&quot;.</p>
<p>I could implement a custom <code>DateTypeAdapter</code> but I am looking for a cleaner way to achieve that. Simply changing the <code>DateFormat</code> would be great.</p>