Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It is JSON feed from .Net service. I'm using this code:</p> <pre><code>public class GsonHelper { public static Gson createWcfGson() { GsonBuilder gsonb = new GsonBuilder(); gsonb.registerTypeAdapter(Date.class, new WcfDateDeserializer()); Gson gson = gsonb.create(); return gson; } private static class WcfDateDeserializer implements JsonDeserializer&lt;Date&gt;, JsonSerializer&lt;Date&gt; { public Date deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { String JSONDateToMilliseconds = "\\/(Date\\((.*?)(\\+.*)?\\))\\/"; Pattern pattern = Pattern.compile(JSONDateToMilliseconds); Matcher matcher = pattern.matcher(json.getAsJsonPrimitive().getAsString()); String result = matcher.replaceAll("$2"); return new Date(new Long(result)); } @Override public JsonElement serialize(Date date, Type arg1, JsonSerializationContext arg2) { return new JsonPrimitive("/Date(" + date.getTime() + ")/"); } } } </code></pre> <p>It registers custom serializer and deserializer for <code>Date</code> type. Using is simple: <code>Gson gson = GsonHelper.createWcfGson();</code> and do what you want.</p> <p><strong>Upd:</strong> Sorry, previous example doesn't work with timezones. It's easier to use <a href="http://developer.android.com/reference/java/util/Calendar.html" rel="noreferrer"><code>Calendar</code></a> to take into account timezone offset. Code will look like this:</p> <pre><code>public class GsonHelper { public static Gson createWcfGson() { GsonBuilder gsonb = new GsonBuilder(); gsonb.registerTypeAdapter(Date.class, new WcfCalendarDeserializer ()); Gson gson = gsonb.create(); return gson; } public static class WcfCalendarDeserializer implements JsonDeserializer&lt;Calendar&gt;, JsonSerializer&lt;Calendar&gt; { public Calendar deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { String JSONDateToMilliseconds = "\\/(Date\\((.*?)(\\+.*)?\\))\\/"; Pattern pattern = Pattern.compile(JSONDateToMilliseconds); Matcher matcher = pattern.matcher(json.getAsJsonPrimitive().getAsString()); matcher.matches(); String tzone = matcher.group(3); String result = matcher.replaceAll("$2"); Calendar calendar = new GregorianCalendar(); calendar.setTimeZone(TimeZone.getTimeZone("GMT" + tzone)); calendar.setTimeInMillis(new Long(result)); return calendar; } @Override public JsonElement serialize(Calendar calendar, Type arg1, JsonSerializationContext arg2) { return new JsonPrimitive("/Date(" + calendar.getTimeInMillis() + ")/"); } } } </code></pre> <p>Then you can use returned <code>Calendar</code> object to get hours and minutes (and adjust timezone if needed).</p> <pre><code>calendar.get(Calendar.HOUR_OF_DAY); calendar.get(Calendar.MINUTE); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload