<small id='8LLui'></small><noframes id='8LLui'>

      <i id='8LLui'><tr id='8LLui'><dt id='8LLui'><q id='8LLui'><span id='8LLui'><b id='8LLui'><form id='8LLui'><ins id='8LLui'></ins><ul id='8LLui'></ul><sub id='8LLui'></sub></form><legend id='8LLui'></legend><bdo id='8LLui'><pre id='8LLui'><center id='8LLui'></center></pre></bdo></b><th id='8LLui'></th></span></q></dt></tr></i><div id='8LLui'><tfoot id='8LLui'></tfoot><dl id='8LLui'><fieldset id='8LLui'></fieldset></dl></div>
      <legend id='8LLui'><style id='8LLui'><dir id='8LLui'><q id='8LLui'></q></dir></style></legend>
          <bdo id='8LLui'></bdo><ul id='8LLui'></ul>
        <tfoot id='8LLui'></tfoot>
      1. 在 WPF/XAML 中显示本地时区的时间

        时间:2023-08-25
          <bdo id='m3MAr'></bdo><ul id='m3MAr'></ul>

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

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

                  <tfoot id='m3MAr'></tfoot>

                    <tbody id='m3MAr'></tbody>
                  <legend id='m3MAr'><style id='m3MAr'><dir id='m3MAr'><q id='m3MAr'></q></dir></style></legend>
                1. 本文介绍了在 WPF/XAML 中显示本地时区的时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我的应用程序跨多个不同设备同步数据.出于这个原因,它将所有日期存储在 UTC 时区中,以说明可能设置为不同时区的不同设备.

                  My application synchronises data across several different devices. For this reason it stores all dates in the UTC time-zone to account for different devices possibly being set to different time zones.

                  问题在于,当我读回日期并显示它们时,它们似乎不正确(大多数用户都在英国夏令时,所以他们晚了一个小时).

                  The trouble is that when I read the dates back out and display them they appear to be incorrect (most of the users are on British Summer Time so they're an hour behind).

                  <TextBlock Margin="5" Style="{StaticResource SmallTextblockStyle}">
                      <Run Text="Last Updated:" />
                      <Run Text="{Binding Path=Submitted}" />
                  </TextBlock>
                  

                  我是否需要手动覆盖 UI 线程的 set CurrentCulture 属性?我知道我必须在 Silverlight 中执行此操作.

                  Do I need to manually override set CurrentCulture property of the UI thread? I know I have to do this in Silverlight.

                  推荐答案

                  您是否将Utc"指定为 DateTime.Kind 解析存储的 DateTime 并将其转换为 DateTime.ToLocalTime()?

                  Are you specifying "Utc" as DateTime.Kind when parsing the stored DateTime and also converting it to DateTime.ToLocalTime()?

                  public DateTime Submitted {
                    get {
                      DateTime utcTime = DateTime.SpecifyKind(DateTime.Parse(/*"Your Stored val from DB"*/), DateTimeKind.Utc);
                  
                      return utcTime.ToLocalTime();
                    }
                  
                    set {
                      ...
                    }
                  }
                  

                  ^^ 对我来说很好用

                  更新:

                  class UtcToLocalDateTimeConverter : IValueConverter
                    {
                      public object Convert(object value, Type targetType, object parameter, CultureInfo culture) {
                        return DateTime.SpecifyKind(DateTime.Parse(value.ToString()), DateTimeKind.Utc).ToLocalTime();
                      }
                  
                      public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) {
                        throw new NotImplementedException();
                      }
                    }
                  

                  xaml:

                  <Window.Resources>
                    <local:UtcToLocalDateTimeConverter x:Key="UtcToLocalDateTimeConverter" />
                  </Window.Resources>
                  ...
                  <TextBlock Text="{Binding Submitted, Converter={StaticResource UtcToLocalDateTimeConverter}}" />
                  

                  这篇关于在 WPF/XAML 中显示本地时区的时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:.resx vs 数据库 vs 提供本地化/全球化的自定义解决 下一篇:App_LocalResources 如何与 MVC 一起工作?

                  相关文章

                  最新文章

                2. <tfoot id='QDcgL'></tfoot>

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

                      • <bdo id='QDcgL'></bdo><ul id='QDcgL'></ul>

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

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