Wrong time zone in the Web-app

  1. 6 weeks ago

    Val K

    Sep 10 Pre-Release Testers, Xojo Pro
    Edited 6 weeks ago

    Hi, guys,

    I have a little problem that I am not sure how to solve.

    I have the following code in my web app

    Dim d As New Date
    
    s = s + str(d.ShortDate) + "  " +  str(d.ShortTime) + EndOfLine + EndOfLine + EndOfLine
    

    When I just Run the code, the time is displayed correctly (for example, 2:50 pm)

    When I deploy the application, the time is five hours later (for example, 7:50 pm).

    What is the way to have this discrepancy fixed?

    Thank you in advance,

    Val

  2. Paul B

    Sep 10 Pre-Release Testers, Xojo Pro Europe (UK, Somerset)

    This is likely the time difference for your server for where it is located. If you have control over it you could change its timezone to that which you require.

  3. Tim H

    Sep 10 Pre-Release Testers Portland, OR USA

    Use Session.GMTOffset to adjust times to the user's timezone.

  4. James D

    Sep 10 Pre-Release Testers, Xojo Pro Europe (Switzerland)

    What time zone do you want to use, the server or that of the user who visits your site?

  5. Michel B

    Sep 10 Pre-Release Testers, Xojo Pro RubberViews.com
    Edited 6 weeks ago

    This will set the Hashtag with "TZ:" followed by the time offset in minutes. For instance in France where I am with daylight saving time, it is -120.

    You get this value with the Session. HastagChanged event, and after a split around "TZ:" you have your user offset from UTC.

    If you are familiar with Websdk you can do it more elegantly, but it goes beyond the scope of this discussion.

    Sub Shown() Handles Shown
      Dim JS as string
      js = js + "var offset = new Date().getTimezoneOffset();"
      js = js + "location.hash = 'TZ:'+offset"
      self.ExecuteJavaScript(js)
    End Sub
  6. 5 weeks ago

    Val K

    Sep 17 Pre-Release Testers, Xojo Pro

    HI, everyone,

    Thank you for the advice. I am trying to find out how to implement the solutions you have suggested.

    Val

  7. Tim H

    Sep 17 Pre-Release Testers Portland, OR USA

    It should be as simple as

    dim d as New Date
    d.GMTOffset = Session.GMTOffset
  8. Michel B

    Sep 17 Pre-Release Testers, Xojo Pro RubberViews.com

    @Tim H It should be as simple as
    dim d as New Date d.GMTOffset = Session.GMTOffset

    Much simpler indeed :D

or Sign Up to reply!