I need to programmatically access the text displayed by the dynamic text Document DateSaved property.
I believe ArcGIS gets this information using IDocumentInfo2.DateSaved. However, the latter returns an Object and not an ITimeInstant or ITime as I would have expected. Furthermore, there is no documentation on how to handle this "Object".
How does one turn the Object into the text string that ArcMap displays in dynamic text elements? I wasn't able to cast the returned Object to ITimeInstant or ITime, or to set it as a Date. The object seems to be a Double. I use VB.NET.
The property returns an Object because not all languages have a Date data type and the ones that do vary in its implementation. Dates can be converted to an equivalent double precision number, which is what the property does because all languages should have some implementation of a double precision data type. In .NET you can use this to get the value:
Dim d As Date = Date.FromOADate(docInfo.DateSaved)
I gave your explanation of why IDocumentInfo2.DateSaved returns an Object a little bit more thoughts and think it would make a lot of sense if that interface and member had been developed by Esri prior to ITime, but they were both released with ArcGIS 10.
Doesn't this mean that Esri could have returned ITime instead of Object as ITime seems to be available for all programming languages supported by ArcGIS? Why go the extra step?
Handling dates as double precision values for cross-language/platform use is pretty standard. My guess would be that they decided to keep it simple as opposed to wrapping the return value in even more COM overhead. It's also just as likely that whoever designed the IDocumentInfo2 interface wasn't even aware of the ITime interface or that they didn't really think about it too much at all. Only ESRI really knows why they implemented it this way.