问题
Does anyone know how to convert these string hex values back into DateTime values?
Property my_DateProperty (System.String) = 0x01c9874e|0x98f28800
//l_item is SPListItem
Hashtable l_properties = l_item.Properties;
if (l_properties != null)
{
object l_value = null;
foreach (string l_key in l_properties.Keys)
{
l_value = l_properties[l_key];
Splogger.log("Property " + l_key + " (" + l_value.GetType().ToString() + ") = " + l_value.ToString());
}
}
回答1:
I discovered recently that this seems to occur only on Office 2007 documents (for other file types, the value is a standard string format for a date). The answer is that the hexadecimal value represents the number of ticks since the 1/1/1600. Here is a conversion that worked for me:
Dim dateVal as DateTime = New DateTime(Long.Parse(dateText.Replace("0x", "").Replace("|", ""), System.Globalization.NumberStyles.HexNumber)).AddYears(1600)
回答2:
Could be you that the datetime is being converted into an "invariant" date by the ToString. See this.
来源:https://stackoverflow.com/questions/521078/splistitem-properties-datetime-fields-are-in-weird-hex-format