Pregunta

I was wondering how to set the DateTime to a specific culture, and also take into account the current time zone. My reason for this is that someone using the en-US culture may be in the United States, but travel to Russia, and I would like the DateTime to reflect the en-US standard (which will be the users device settings) but reflect the current time when in a Russian time zone. Is this possible, and if so, how might I accomplish this?

So far I am simply setting

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

Does this automatically reflect the current time based on whatever time zone the user may be in? And also, how might I display this correctly based on the users device culture settings?

¿Fue útil?

Solución

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.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top