Select to view content in your preferred language

Getting Date from version 10 using 1.2 api

654
2
09-03-2010 01:50 PM
caseycupp
Deactivated User
How do I convert 1144368000000 to 4/7/2006 ?

We have a mapservice that is using ArcGIS 10. We are are using the 1.2 arcgis silverlight api.

The identify task is returning readable dates, however the query task is returning dates in a long format. I can replicate the results by using the browser query task against the RestAPI. If I return JSON I get 1144368000000, however if I return HTML i see the date 4/7/2006.

I have not been able to figure out how to get this to convert.
I've tried assuming this is Ticks so doing...
DateTime dt = new DateTime(1144368000000);  but that doesn't work. (it only works out to a day and a half of ticks)

Both of these options return 1/2/1601
DateTime stest = DateTime.FromFileTime(1144368000000)
DateTime stest2 = DateTime.FromFileTimeUtc(1144368000000)


I have also tried pushing it into a JSONValue and JSONObject but without success.

I see there is a new DateTimeConverter class in the 2.0 version (ESRI.ArcGIS.Client.Toolkit.Utilities), but surely there is a way to get this to convert without having to upgrade the API.

casey
0 Kudos
2 Replies
DominiqueBroux
Esri Frequent Contributor
It looks like an Unix time based on seconds since standard epoch of 1/1/1970 (or in ms in your case)

You can get the date with :
DateTime dt = UnixTimeToDateTime(1144368000000 / 1000);

UnixTimeToDateTime method:
 
private static DateTime origin = new DateTime(1970, 1, 1);
public static DateTime UnixTimeToDateTime(long timespan)
{
  return origin.AddSeconds(timespan);
} 
0 Kudos
caseycupp
Deactivated User
That was perfect..I was so close but kept missing.
Thanks!
0 Kudos