SPListItem.Properties 日期时间字段采用奇怪的十六进制格式 [英] SPListItem.Properties DateTime Fields are in weird Hex format

查看:50
本文介绍了SPListItem.Properties 日期时间字段采用奇怪的十六进制格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有谁知道如何将这些字符串十六进制值转换回 DateTime 值?

Does anyone know how to convert these string hex values back into DateTime values?

属性 my_DateProperty (System.String) = 0x01c9874e|0x98f28800

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());
    }
}

推荐答案

我最近发现这似乎只发生在 Office 2007 文档上(对于其他文件类型,该值是日期的标准字符串格式).答案是十六进制值表示自 1/1/1600 以来的刻度数.这是一个对我有用的转换:

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)

Dim dateVal as DateTime = New DateTime(Long.Parse(dateText.Replace("0x", "").Replace("|", ""), System.Globalization.NumberStyles.HexNumber)).AddYears(1600)

这篇关于SPListItem.Properties 日期时间字段采用奇怪的十六进制格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆