3

I'm modifying the time zone by replacing the file /etc/locatime by one in /usr/share/zoneinfo in a C#/Mono application, it nearly works.

Here is my code:

Console.WriteLine("a) Current Time zone: {0}", TimeZoneInfo.Local.StandardName);
Console.WriteLine("a) Now: {0}", DateTime.Now);

// Changing /etc/locatime from CET to PST ...

TimeZoneInfo.ClearCachedData();

Console.WriteLine("b) Current Time zone: {0}", TimeZoneInfo.Local.StandardName);
Console.WriteLine("b) Now: {0}", DateTime.Now);

And here is the ouput:

a) Current Time zone: CET
a) Now: 10/20/2012 2:00:26 PM
b) Current Time zone: PST
b) Now: 10/20/2012 2:00:26 PM

As you can see the time zone is correct but DateTime.Now, which should return the local time, doesn't work and returns twice the same value.

Here is the version of mono I'm using:

user@ubuntu:~$ mono -V
Mono JIT compiler version 2.10.8.1 (Debian 2.10.8.1-1ubuntu2.2)
    TLS:           __thread
    SIGSEGV:       altstack
    Notifications: epoll
    Architecture:  x86
    Disabled:      none
    Misc:          softdebug 
    LLVM:          supported, not enabled.
    GC:            Included Boehm (with typed GC and Parallel Mark)

Does someone have an idea about this issue?

4

1 回答 1

1

正如 Celada 指出的那样——大多数 C 库只读取一次。 在 Linux 上DateTime.Now调用。gettimeofday()

在 Windows 上也是如此,您甚至不需要任何 .NET 应用程序,只需打开 Windows Power Shell ,键入date,然后在控制面板中更改时区并date在同一个 Power Shell 窗口中再次键入。它不接受时区更改。只有新启动的进程才能获得新的时区。

于 2012-10-30T23:12:28.623 回答