SPListItem.Properties DateTime Fields are in weird Hex format

╄→尐↘猪︶ㄣ 提交于 2019-12-23 20:36:50

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!