DateTime.Now returning values 1 hour later than expected on mobile.

Unity 2018.2.0b3.

I’m creating a project in Unity, on .NET 4.6 in C#, using IL2CPP. I need to get the UTC Offset of the user in seconds, and to do so I am using the following code:

UserData.Offset = (float)(System.DateTime.Now - System.DateTime.UtcNow).TotalSeconds;

When I trace out the values of DateTime.Now and DateTime.UtcNow, they are completely correct in editor (I’m in the AEST timezone, so a +10 hour offset). When I attempt the same on iOS and Android (a model of iPad and an Xperia XZ), the UtcNow value returns correctly, but the Now value is always an hour forward (+11 hour offset). This doesn’t make any sense at all, as we should not be in DST.

I have attempted calling;

System.Globalization.CultureInfo.CurrentCulture.ClearCachedData();

But this does not change the values at all.

Where is the fault at? This is a pretty critical part of the app which I need to resolve asap.

This should work properly. Can you try it with Mono on Android as well? If it works there, we’re probably seeing some kind of bug in the interaction with IL2CPP and the OS. In that case, please submit a bug report.

Maybe you could use DateTimeOffset.Now Property (System) | Microsoft Learn (DateTimeOffset.Now) and then interrogate the ‘offset’ variable instead.