• <small id='mjEDR'></small><noframes id='mjEDR'>

    <tfoot id='mjEDR'></tfoot>

      <bdo id='mjEDR'></bdo><ul id='mjEDR'></ul>
    <legend id='mjEDR'><style id='mjEDR'><dir id='mjEDR'><q id='mjEDR'></q></dir></style></legend>
  • <i id='mjEDR'><tr id='mjEDR'><dt id='mjEDR'><q id='mjEDR'><span id='mjEDR'><b id='mjEDR'><form id='mjEDR'><ins id='mjEDR'></ins><ul id='mjEDR'></ul><sub id='mjEDR'></sub></form><legend id='mjEDR'></legend><bdo id='mjEDR'><pre id='mjEDR'><center id='mjEDR'></center></pre></bdo></b><th id='mjEDR'></th></span></q></dt></tr></i><div id='mjEDR'><tfoot id='mjEDR'></tfoot><dl id='mjEDR'><fieldset id='mjEDR'></fieldset></dl></div>

        将 LDAP 中的 WhenChanged 属性(通用时间)转换为 C# 中的 DateTime

        Converting the WhenChanged attribute (Generalized-Time) in LDAP to a DateTime in C#(将 LDAP 中的 WhenChanged 属性(通用时间)转换为 C# 中的 DateTime)

        <i id='YC1zL'><tr id='YC1zL'><dt id='YC1zL'><q id='YC1zL'><span id='YC1zL'><b id='YC1zL'><form id='YC1zL'><ins id='YC1zL'></ins><ul id='YC1zL'></ul><sub id='YC1zL'></sub></form><legend id='YC1zL'></legend><bdo id='YC1zL'><pre id='YC1zL'><center id='YC1zL'></center></pre></bdo></b><th id='YC1zL'></th></span></q></dt></tr></i><div id='YC1zL'><tfoot id='YC1zL'></tfoot><dl id='YC1zL'><fieldset id='YC1zL'></fieldset></dl></div>

        <small id='YC1zL'></small><noframes id='YC1zL'>

            <tbody id='YC1zL'></tbody>
            <bdo id='YC1zL'></bdo><ul id='YC1zL'></ul>
                <tfoot id='YC1zL'></tfoot><legend id='YC1zL'><style id='YC1zL'><dir id='YC1zL'><q id='YC1zL'></q></dir></style></legend>
                • 本文介绍了将 LDAP 中的 WhenChanged 属性(通用时间)转换为 C# 中的 DateTime的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我最近从使用 S.DS 命名空间(使用 ADSI)切换到 S.SD.Protocol 命名空间.唯一的问题是 ADSI 为我处理了广义时间到日期时间的转换.现在,我为 WhenChanged 属性返回了20070828085401.0Z"的值.DateTime.Parse() 不会转换这个,还有其他方法吗?

                  I recently switch from using S.DS namespace (which uses ADSI) to the S.SD.Protocol namespace. The only problem is that ADSI handled the conversion of Generalized-Time to a DateTime for me. Now I'm getting back a value of "20070828085401.0Z" for the WhenChanged attribute. DateTime.Parse() will not convert this so is there another way?

                  推荐答案

                  您得到的格式接近往返日期时间模式 ("o") 和通用可排序往返日期时间模式 ("u") 标准日期时间格式字符串,如此处所述.

                  The format you are getting is close to the round trip date time pattern ("o") and universal sortable round trip date time pattern ("u") standard date time format strings as described here.

                  一个笨拙的解决方案是按摩你得到的字符串以适应模式,然后使用带有 ParseExact.

                  One kludgy solution would be to massage the string you get to fit the pattern and then use the "o" or "u" standard format string with ParseExact.

                  更好的方法是构造一个自定义格式字符串与您已经获得的数据相匹配.在标准日期时间格式字符串页面的标准格式字符串如何工作"部分中,您将看到等效于o"和u"的完整自定义格式字符串.这应该会给你一个好的开始.

                  A better way would be to construct a custom format string that matches the data you are already getting. In the "How Standard Format Strings Work" section of the standard date time format strings page you'll see the full custom formatting strings equivalent to "o" and "u". That should give you a good start.

                  编辑:添加代码

                  string format = "yyyyMMddHHmmss.f'Z'";
                  
                  string target = "20070828085401.0Z";
                  
                  DateTime d = DateTime.ParseExact(target, format, CultureInfo.InvariantCulture);
                  

                  <小时>

                  在评论中 lixonn 观察到,使用上面的格式字符串,ParseExact 不会成功解析像 199412160532-0500 这样的时间字符串.


                  In the comments lixonn observes that, using the format string above, ParseExact will not successfully parse a time string like 199412160532-0500.

                  它也不会解析许多其他有效字符串,例如没有尾随Zulu"指示符的时间 (20070828085401.0);没有小数部分的时间 (20070828085401Z) 以及将分钟和秒表示为小数部分的时间 (2007082808.90028Z).

                  It also won't parse a number of other valid strings such as times without the trailing 'Zulu' indicator (20070828085401.0); times without a fractional part (20070828085401Z) and times that represent minutes and seconds as a fractional hour (2007082808.90028Z).

                  通过将硬编码的 'Z' 替换为 K 自定义说明符,它将接受Z"、-0500 之类的偏移量,什么都没有.额外的灵活性是否是一件好事将取决于您的应用程序.

                  The format string can be made slightly more forgiving by replacing the hard-coded 'Z' with the K custom specifier which will accept 'Z', an offset like -0500, and nothing. Whether that additional flexibility is a good thing will depend on your application.

                  请注意,即使使用 K 说明符,Lixonn 的字符串也不会被成功解析,因为它缺少与格式字符串的 .f 组件匹配的小数部分.

                  Note that even with the K specifier Lixonn's string won't be parsed successfully since it lacks a fractional part to match the .f component of the format string.

                  这篇关于将 LDAP 中的 WhenChanged 属性(通用时间)转换为 C# 中的 DateTime的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Adding and removing users from Active Directory groups in .NET(在 .NET 中的 Active Directory 组中添加和删除用户)
                  set equality in linq(在 linq 中设置相等)
                  HashSet conversion to List(HashSet 转换为 List)
                  How to set timeout for webBrowser navigate event(如何为 webBrowser 导航事件设置超时)
                  Test whether two IEnumerablelt;Tgt; have the same values with the same frequencies(测试两个IEnumerablelt;Tgt;具有相同频率的相同值)
                  How do you determine if two HashSets are equal (by value, not by reference)?(您如何确定两个 HashSet 是否相等(按值,而不是按引用)?)

                    <legend id='VMuDa'><style id='VMuDa'><dir id='VMuDa'><q id='VMuDa'></q></dir></style></legend>

                    <small id='VMuDa'></small><noframes id='VMuDa'>

                    • <bdo id='VMuDa'></bdo><ul id='VMuDa'></ul>
                      <i id='VMuDa'><tr id='VMuDa'><dt id='VMuDa'><q id='VMuDa'><span id='VMuDa'><b id='VMuDa'><form id='VMuDa'><ins id='VMuDa'></ins><ul id='VMuDa'></ul><sub id='VMuDa'></sub></form><legend id='VMuDa'></legend><bdo id='VMuDa'><pre id='VMuDa'><center id='VMuDa'></center></pre></bdo></b><th id='VMuDa'></th></span></q></dt></tr></i><div id='VMuDa'><tfoot id='VMuDa'></tfoot><dl id='VMuDa'><fieldset id='VMuDa'></fieldset></dl></div>
                      • <tfoot id='VMuDa'></tfoot>

                              <tbody id='VMuDa'></tbody>