Search Unity

Android Datetime.Now is wrong

Discussion in 'Android' started by Nolemonpledge, Aug 15, 2017.

  1. Nolemonpledge

    Nolemonpledge

    Joined:
    Apr 23, 2017
    Posts:
    7
    Let's say it's 6pm today on Tuesday, August 15th. I show DateTime.Now.To String() and DateTime.UtcNow.To String() in some txt fields. When I run the unity editor it shows the correct date and DateTime.Now as 6pm and dateTime.UtcNow as 10pm (est time zone). But when I build and run it on my HTC one android phone it shows the right date but shows the time as 22:00:00 for DateTime.Now as well as for DateTime.UtcNow. I don't understand why the time isn't showing correct on my android. Even if I manually change timezones in my phone and run the app it still shows 22:00:00. That should at least change it, but it doesn't.

    Any idea why this is happening?
     
  2. Ericroy

    Ericroy

    Joined:
    Oct 9, 2010
    Posts:
    11
    I filed a bug report (Case 943047) for this. If you build with Net 4.6, DateTime.Now doesn't work correctly. If you build with Net 3.5, it works as it should.
     
  3. Nolemonpledge

    Nolemonpledge

    Joined:
    Apr 23, 2017
    Posts:
    7
    OK cool, it works now. But I noticed using System.Globalization.CultureInfo.CurrentCulture.ClearCachedData(); doesn't work for .NET 3.5. for I need a way to know if I am changing timezones and Timezoneinfo doesn't work in .NET 3.5 either. Damn!
     
  4. cyliax

    cyliax

    Joined:
    Feb 25, 2014
    Posts:
    18
    Bump, same here. Local and UTC time from DateTime.Now and UtcNow are always the same on Android (7). And TimeZone.CurrentTimeZone.StandardName is always UTC as well. I don't get it, what's wrong? Can't go back to NET 3.5.
     
  5. Nolemonpledge

    Nolemonpledge

    Joined:
    Apr 23, 2017
    Posts:
    7
    Yeah .NET 4.6 is broken. I tried for awhile to figure it out but no success. Going back to 3.5 was fine for me though.
     
  6. CptDustmite

    CptDustmite

    Joined:
    Jun 17, 2014
    Posts:
    61
    This is a major bug. We have already upgraded our project to the .NET 4.6 version and it's too late to go back now. Many of our features rely on local user time.
     
  7. scarffy

    scarffy

    Joined:
    Jan 15, 2013
    Posts:
    25
    Is there any work around for this?
     
  8. Thom_Denick

    Thom_Denick

    Joined:
    May 19, 2014
    Posts:
    15
    Hey guys, you really need to fix this! System Time is really important!
     
  9. Evaldas_Unity

    Evaldas_Unity

    Unity Technologies

    Joined:
    Jun 23, 2016
    Posts:
    85