3

/etc/locatimeC#/Mono アプリケーションでファイルを 1 つに置き換えることでタイム ゾーンを変更していますが/usr/share/zoneinfo、ほぼ機能します。

これが私のコードです:

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);

そして、ここに出力があります:

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

ご覧のとおり、タイム ゾーンは正しいですがDateTime.Now、ローカル タイムを返すはずの が機能せず、同じ値を 2 回返します。

私が使用しているモノのバージョンは次のとおりです。

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)

誰かがこの問題について考えを持っていますか?

4

1 に答える 1

1

Celada が指摘したように、ほとんどの C ライブラリは一度しか読み取れません。 DateTime.NowLinux で呼び出しますgettimeofday()

これは Windows でも同じです。.NET アプリケーションは必要ありません。単純に Windows Power Shell を開いてdateと入力し、コントロール パネルでタイムゾーンを変更しdateて、同じ Power Shell ウィンドウにもう一度入力します。タイムゾーンの変更は反映されません。新しく開始されたプロセスのみが新しいタイム ゾーンを取得します。

于 2012-10-30T23:12:28.623 に答える