Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Bug DateTime.Now in WebGL Build

Discussion in 'WebGL' started by C0lonnello, Sep 4, 2023.

  1. C0lonnello

    C0lonnello

    Joined:
    Nov 7, 2022
    Posts:
    24
    Hi all,

    I'm having an issue regarding DateTime.Now function.

    In my editor project, the function works properly and it returns the correct local time.

    However, in my WebGL build, which is hosted on aws, DateTime.Now returns 1 hour earlier than my local time, for some reasons.

    Why don't it read my local machine time? It is something that depends on the host server location? (Don't think so since the application is still running on my browser)
    Of course I can hard-code a "+1" hour in the function but I'd like to understand why and if maybe it is something related to daylight saving time hours?
     
    Last edited: Sep 4, 2023
  2. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    3,899
    I think browsers can have their own timezone setting. It should default to your current locale but perhaps that isn't set correctly, or manually overriding in the browser?

    In any case, do test WebGL apps with all common browsers. Especially if you run into an odd issue it's best practice to first confirm whether this appears only in one or some browsers. If so, it's a browser-specific issue. If all browsers exhibit the same behaviour, it's more likely an issue with the app.
     
  3. C0lonnello

    C0lonnello

    Joined:
    Nov 7, 2022
    Posts:
    24
    I tried it with Chrome and Edge and both of them seems to have the same error.

    At the same time, I tried to run a simple javascript script in the browser console where I invoke Date() and the result is correct in this case, it reports my correct time (GMT +2) in this case, if that could count somehow.
     
  4. ajf_bgc

    ajf_bgc

    Joined:
    Dec 28, 2022
    Posts:
    1
    If you call DateTime.UtcNow() on both environments, do they both return the same time (which they should)?
     
  5. C0lonnello

    C0lonnello

    Joined:
    Nov 7, 2022
    Posts:
    24
    Yes, they both returns the same time with UtcNow.