Skip to content Skip to sidebar Skip to footer

Json Date Converted From Asp - Need Converting To Java

I have a slight problem with my JSON string which I have converted from ASP.NET. The JSON string that C# has converted for me looks like this: /Date(1338199919727)\/ I guess it con

Solution 1:

but how do i get a java-date out of this huge integer?

Ah, that part's easy:

Date dt = newDate(1338199919727L);

You are quite right, it's milliseconds-since-The-Epoch (Jan 1st at midnight, 1970). And Java's Date object has a constructor that accepts that very value.

In general, most JSON parsers have the concept of a "reviver" function or class that you can pass to them, which will let you pre-process values as the JSON is being deserialized. I don't know Android's JSON parser well enough to know if it has one. If not (which would be a bit backward), you'd have to walk the resulting object graph looking for properties that had become strings and converting them to dates after-the fact.

Solution 2:

I hope this is what you need

long Ldate = 1338199919727L;
    Datedate = newDate(Ldate * 1000);
    String strdate = (String) DateFormat.format("MM/dd/yy h:mmaa", date);

Post a Comment for "Json Date Converted From Asp - Need Converting To Java"