0

Or is this even possible?

As a side question and the reason for this question coming into existence for me is to understand what happens to the DateTime object when user changes Windows culture settings at runtime?

xnp
  • 51
  • 2
  • 6
  • 4
    What do you mean? A `DateTime` value has no culture. If you format it according to a specific culture, you no longer have a `DateTime` value. You have a `string` value. Naturally, `string` values have no mechanism for reporting the culture used to create them. You would have to store the culture information separately. What is it you are actually asking here? – Peter Duniho Nov 07 '15 at 01:51
  • I can see my quoestion was a bit unclear, sorry about that. So the DateTime object is always assumed to be local time? I just dont understand why date.ToLocalTime().ToLocalTime() changes the value only once? – xnp Nov 07 '15 at 02:01
  • 1
    DateTime.SpecifyKind allows you to specify it is local or UTC. ToLocalTime() will convert a UTC time to local. – James Nov 07 '15 at 02:04
  • So I actually tested during run time the way it would change and it seems as though in order for it to grab a new LocalTime for proper conversion based on the system time, you would have to instantiate a new DateTime object so that the DateTime object could grab the system's properties at creation. This though, was not thoroughly tested just my quick results from a very rough rough test. I deleted my answer because my findings contradict it. – Joseph Bisaillon Nov 07 '15 at 02:27
  • PS Use `DateTimeOffset`, it's better in so many ways. – Ian Mercer Nov 07 '15 at 04:57

2 Answers2

2

What happens to the DateTime object when user changes Windows culture settings at runtime?

Nothing. Any existing values of DateTime are unchanged.

the DateTime object is always assumed to be local time?

No. A DateTime value can be either a "local" value, a "UTC" value, or a value of "unspecified" kind.

I just dont understand why date.ToLocalTime().ToLocalTime() changes the value only once?

Methods on DateTime that convert between the two check what kind of DateTime value the current value represents. If the current value is already of the kind being requested, the method just returns the current value.

So once you've called ToLocalTime(), you now have a "local" kind of DateTime, and if you call ToLocalTime() again you're just going to get that same value back.

Peter Duniho
  • 68,759
  • 7
  • 102
  • 136
0
  1. Value of DateTime field never changed when user changes windows culture setting at runtime.

  2. No, we cannot assume DateTime value as a local time.

Deepak gupta
  • 1,938
  • 11
  • 11