• <i id='92a3Q'><tr id='92a3Q'><dt id='92a3Q'><q id='92a3Q'><span id='92a3Q'><b id='92a3Q'><form id='92a3Q'><ins id='92a3Q'></ins><ul id='92a3Q'></ul><sub id='92a3Q'></sub></form><legend id='92a3Q'></legend><bdo id='92a3Q'><pre id='92a3Q'><center id='92a3Q'></center></pre></bdo></b><th id='92a3Q'></th></span></q></dt></tr></i><div id='92a3Q'><tfoot id='92a3Q'></tfoot><dl id='92a3Q'><fieldset id='92a3Q'></fieldset></dl></div>
    1. <small id='92a3Q'></small><noframes id='92a3Q'>

    2. <legend id='92a3Q'><style id='92a3Q'><dir id='92a3Q'><q id='92a3Q'></q></dir></style></legend>
    3. <tfoot id='92a3Q'></tfoot>
        <bdo id='92a3Q'></bdo><ul id='92a3Q'></ul>

      1. 如何使用缩写的时区显示 DateTime?

        How to display DateTime with an abbreviated Time Zone?(如何使用缩写的时区显示 DateTime?)
          <bdo id='WNTQT'></bdo><ul id='WNTQT'></ul>

          1. <legend id='WNTQT'><style id='WNTQT'><dir id='WNTQT'><q id='WNTQT'></q></dir></style></legend>
            <tfoot id='WNTQT'></tfoot>

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

              <tbody id='WNTQT'></tbody>
          2. <i id='WNTQT'><tr id='WNTQT'><dt id='WNTQT'><q id='WNTQT'><span id='WNTQT'><b id='WNTQT'><form id='WNTQT'><ins id='WNTQT'></ins><ul id='WNTQT'></ul><sub id='WNTQT'></sub></form><legend id='WNTQT'></legend><bdo id='WNTQT'><pre id='WNTQT'><center id='WNTQT'></center></pre></bdo></b><th id='WNTQT'></th></span></q></dt></tr></i><div id='WNTQT'><tfoot id='WNTQT'></tfoot><dl id='WNTQT'><fieldset id='WNTQT'></fieldset></dl></div>
                • 本文介绍了如何使用缩写的时区显示 DateTime?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  我知道 System.TimeZone 类以及 DateTime.ToString() 方法.我找不到的是一种将 DateTime 转换为字符串的方法,该字符串除了时间和日期信息之外,还包含三个字母的时区缩写(实际上,与 StackOverflow 的相对工具提示大致相同)时间显示有效).

                  I am aware of the System.TimeZone class as well as the many uses of the DateTime.ToString() method. What I haven't been able to find is a way to convert a DateTime to a string that, in addition to the time and date info, contains the three-letter Time Zone abbreviation (in fact, much the same way StackOverflow's tooltips for relative time display works).

                  为了让每个人都能轻松学习和使用示例,让我们继续 StackOverflow 示例.如果您查看显示相对时间的工具提示,它会显示完整日期、时间(包括 12 小时格式的秒数)、AM/PM 名称,然后是三个字母的时区缩写(在他们的情况下,协调世界时).我意识到我可以通过使用内置方法轻松获取 GMT 或 UTC,但我真正想要的是本地时间 —在这种情况下,在 Web 服务器上.

                  To make an example easy for everyone to follow as well as consume, let's continue with the StackOverflow example. If you look at the tooltip that displays on relative times, it displays with the full date, the time including seconds in twelve-hour format, an AM/PM designation, and then the three-letter Time Zone abbreviation (in their case, Coordinated Universal Time). I realize I could easily get GMT or UTC by using the built-in methods, but what I really want is the time as it is locally — in this case, on a web server.

                  如果我们的网络服务器运行的是 Windows Server 2k3 并且它的时区设置为 CST(或者,直到 夏令时切换回来,是 CDT 吗?),我希望我们的 ASP.NET Web 应用程序显示相对于该时区的日期时间,并格式化为最后显示CST".我意识到我可以轻松地对其进行硬编码,但出于稳健性的考虑,我真的更喜欢基于运行代码的操作系统环境设置的服务器的解决方案.

                  If our web server is running Windows Server 2k3 and has it's time zone set to CST (or, until daylight saving switches back, CDT is it?), I'd like our ASP.NET web app to display DateTimes relative to that time zone as well as formatted to display a "CST" on the end. I realize I could easily hard-code this, but in the interest of robustness, I'd really prefer a solution based on the server running the code's OS environment settings.

                  现在,除了时区缩写外,我使用以下代码:

                  Right now, I have everything but the time zone abbreviation using the following code:

                  myDateTime.ToString("MM/dd/yyyy hh:mm:ss tt")
                  

                  其中显示:

                  2008 年 10 月 7 日下午 3:40:31

                  10/07/2008 03:40:31 PM

                  我想要的只是(承诺不多!)就是让它说:

                  All I want (and it's not much, promise!) is for it to say:

                  10/07/2008 03:40:31 PM CDT

                  10/07/2008 03:40:31 PM CDT

                  我可以使用 System.TimeZone.CurrentTimeZone 并使用它来正确显示Central Daylight Time"但是......为了简洁起见,这有点太长了.然后我是否坚持编写字符串操作例程来去除空格和任何非大写字母?虽然这可能行得通,但对我来说这似乎令人难以置信......

                  I can use System.TimeZone.CurrentTimeZone and use it to correctly display "Central Daylight Time" but... that's a bit too long for brevity's sake. Am I then stuck writing a string manipulation routine to strip out white-space and any non-uppercase letters? While that might work, that seems incredibly hack to me...

                  谷歌搜索并在此处查看并没有产生任何适用于我的具体问题的内容.

                  Googling and looking around on here did not produce anything applicable to my specific question.

                  推荐答案

                  这是我刚刚为解决这个问题而制作的快速破解方法.

                  Here's my quick hack method I just made to work around this.

                  public static String TimeZoneName(DateTime dt)
                  {
                      String sName = TimeZone.CurrentTimeZone.IsDaylightSavingTime(dt) 
                          ? TimeZone.CurrentTimeZone.DaylightName 
                          : TimeZone.CurrentTimeZone.StandardName;
                  
                      String sNewName = "";
                      String[] sSplit = sName.Split(new char[]{' '});
                      foreach (String s in sSplit)
                          if (s.Length >= 1)
                              sNewName += s.Substring(0, 1);
                  
                      return sNewName;
                  }
                  

                  这篇关于如何使用缩写的时区显示 DateTime?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  Force JsonConvert.SerializeXmlNode to serialize node value as an Integer or a Boolean(强制 JsonConvert.SerializeXmlNode 将节点值序列化为整数或布尔值)
                  Using JSON to Serialize/Deserialize TimeSpan(使用 JSON 序列化/反序列化 TimeSpan)
                  Could not determine JSON object type for type quot;Classquot;(无法确定类型“Class的 JSON 对象类型.)
                  How to deserialize a JSONP response (preferably with JsonTextReader and not a string)?(如何反序列化 JSONP 响应(最好使用 JsonTextReader 而不是字符串)?)
                  how to de-serialize JSON data in which Timestamp it-self contains fields?(如何反序列化时间戳本身包含字段的JSON数据?)
                  JSON.Net custom contract serialization and Collections(JSON.Net 自定义合约序列化和集合)

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

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

                            <tfoot id='SCL51'></tfoot>

                              <tbody id='SCL51'></tbody>