1

我想知道如何将 DateTime 设置为特定的文化,并考虑当前时区。我这样做的原因是,使用 en-US 文化的人可能在美国,但去俄罗斯旅行,我希望 DateTime 反映 en-US 标准(这将是用户设备设置),但反映俄罗斯时区的当前时间。这是可能的,如果是这样,我怎么能做到这一点?

到目前为止,我只是设置

currentTimeTextBlock.Text = DateTime.Today.ToShortDateString();

这是否会根据用户所在的时区自动反映当前时间?而且,如何根据用户的设备文化设置正确显示它?

4

1 回答 1

0

The code you are doing now:

currentTimeTextBlock.Text = DateTime.Today.ToShortDateString();

That will set the current date by the phone's clock, and format it with the user's culture settings. This is probably the best thing to do.

Chances are that the user will probably have set their time zone on their phone appropriately. The date and time settings on Windows Phone 8 look like this:

                  WP8 Date and Time Settings 1   WP8 Date and Time Settings 2

The screen on the right is what it looks like if you change "Set automatically" to "Off". Most users will keep this on. Their phone will automatically update it's time and time zone based on the location.

If they were for some reason to manually set the time zone, then not only would your application be off, but so would everything else on the phone. So I wouldn't try to compensate for that. I know if I were traveling to Russia and my phone didn't update it's time zone, that's probably one of the first things I would do when getting off the plane.

于 2013-10-06T03:32:58.853 回答