アプリなどを開発するブログ

React Native / Swift / Ruby on Railsなどの学習メモ。


Unity .NET4.6 でDateTime.NowがUTCの時刻を返すバグ (iOS / Android)

DateTime.Nowで正しい時刻が取れません。UTC時刻が返ってきます。
TimeZoneInfoでJSTを取得しようとしても駄目。

FileNotFoundException: Could not find file "/usr/share/zoneinfo/JST".
System.IO.FileStream..ctor (System.String path, System.IO.FileMode mode, System.IO.FileAccess access, System.IO.FileShare share, System.Int32 bufferSize, System.Boolean anonymous, System.IO.FileOptions options)

どうやら、タイムゾーン情報のファイルが実行環境に含まれていないことで起こっているみたい。

Unityのフォーラムでも困っている人たち見つけました。
.NET 3.5でやるしかねぇのか。。

https://forum.unity.com/threads/android-datetime-now-is-wrong.488380/