Time Function returns Wrong Time

Discussion in 'ASP General' started by RICHARD BROMBERG, Oct 15, 2005.

  1. I am writing an ASP program that includes a Form.

    When the Form is submitted I use the Date() and Time() functions to put the
    date and time into the Body part of the e-mail.
    The time reported is three hours earlier than the time at which the Form is
    actually submitted.

    I understand these functions are evaluated on the server so the server must
    be in a time zone three hours earlier than where I am .

    Is there any way I can get the local time at the location where the user is
    actually located. ??

    Thanks
    RICHARD BROMBERG, Oct 15, 2005
    #1
    1. Advertising

  2. RICHARD BROMBERG

    Evertjan. Guest

    RICHARD BROMBERG wrote on 15 okt 2005 in
    microsoft.public.inetserver.asp.general:

    > I am writing an ASP program that includes a Form.


    The ASP of the form submitting page is unimportant for your Q.

    The page the form is submitted to should be an .asp page.

    > When the Form is submitted I use the Date() and Time() functions


    Are you sure this is serverside ASP?

    ASP vbscript now() contains both date and time.

    > to
    > put the date and time into the Body part of the e-mail.
    > The time reported is three hours earlier than the time at which the
    > Form is actually submitted.
    >
    > I understand these functions are evaluated on the server


    All ASP code is executed on the server.
    However Date() and Time() could also be clientside VBS on a IE browser.

    > so the server
    > must be in a time zone three hours earlier than where I am .
    >
    > Is there any way I can get the local time at the location where the
    > user is actually located. ??


    If you mean by "ASP program" "ASP vbscript":

    myDateTime = DateAdd("h", 3, Now)

    --
    Evertjan.
    The Netherlands.
    (Replace all crosses with dots in my emailaddress)
    Evertjan., Oct 15, 2005
    #2
    1. Advertising

  3. To the OP, you'll have to forgive Captain A-hole's purposeful lack of
    anything usable in his reply. It's a little game of his, he likes to be as
    diminutive as possible without compromising the overtly disingenuous nature
    of the non-information he 'shares.'

    As for a solution, the most straight-forward way is to create a [JavaScript]
    Date object on the client, call it's getTimezoneOffset() method, and post
    the result to the server in a hidden input, optionally keeping it as part
    of the user's profile data.

    Sadly it's sometimes the case that the user has the time-of-day set for
    his/her geographic area, but has the wrong timezone configured. Further, as
    a matter of logistics more than anything, you can expect the time-of-day
    (UTC) according to any given machine, to vary slightly from your server.

    So if accuracy is of extreme importance, you should post both the timezone
    offset and the time-of-day (UTC) from the client to yourself, convert your
    server time to UTC, and see if they match, +-15 minutes or so. If not,
    inform the user that there is a configuration issue.

    Given that you can trust the timezone offset, acquire it from the client via
    script, and use it to calculate the transaction time-of-day stamp from
    server time. Better yet, always store server-based time-of-day stamp as
    UTC, and adjust it to local time when you render the page.

    Resist the temptation to simply acquire and store the local time-of-day from
    the client. People have been known to forge time-of-day stamps by adjusting
    their system time. Server time is more reliable; storing it as UTC gives
    you an always-known frame of reference, and avoids inaccuracy caused by
    multiple conversions.

    So to correct myself, the most straight-forward way is to use your server's
    time, stored as UTC, and render it as local time when you render the page,
    based on timezone offset.


    -Mark


    (btw, "Evertjan", I'll top-post any time I damn well please, if you have an
    issue, keep it to yourself. See other comments injected into post below...)

    "Evertjan." <> wrote in message
    news:Xns96F0A3A974D3Deejj99@194.109.133.242...
    > RICHARD BROMBERG wrote on 15 okt 2005 in
    > microsoft.public.inetserver.asp.general:
    >
    >> I am writing an ASP program that includes a Form.

    >
    > The ASP of the form submitting page is unimportant for your Q.


    Well now that's not entirely true, is it? Will he not construct that form,
    as well as any event script, in ASP?


    > The page the form is submitted to should be an .asp page.


    Painfully obvious, content == 0.


    >> When the Form is submitted I use the Date() and Time() functions

    >
    > Are you sure this is serverside ASP?


    Yes he's sure, you dimwit, the functions Date() and Time() are both
    supported by VBS -- condescending and stupid is a really poor combination.


    > ASP vbscript now() contains both date and time.
    >
    >> to
    >> put the date and time into the Body part of the e-mail.
    >> The time reported is three hours earlier than the time at which the
    >> Form is actually submitted.
    >>
    >> I understand these functions are evaluated on the server

    >
    > All ASP code is executed on the server.


    No kidding? Wow, I wonder if the OP was making reference to this with his
    statement, "I understand these functions are evaluated on the server". Bah,
    no, couldn't possibly, thank the heavens we have "Evertjan" to set us
    straight on these complex topics.


    > However Date() and Time() could also be clientside VBS on a IE browser.
    >
    >> so the server
    >> must be in a time zone three hours earlier than where I am .
    >>
    >> Is there any way I can get the local time at the location where the
    >> user is actually located. ??

    >
    > If you mean by "ASP program" "ASP vbscript":


    "Program" is a substantially correct term -- was there a point you were
    trying to make? A relevant point? Something that might enhance the
    discussion and leave the OP better-informed? If so, I can't imagine what it
    would be, other than perhaps your asserting your god-given right to waste a
    few dozen bytes of bandwidth... again.


    > myDateTime = DateAdd("h", 3, Now)


    Hey now! There's an inspired solution, hard-code a 3 hour offset on the
    server side -- are you available to, like, write "ASP vbscript" um...
    programs or something? What's your rate? That's the kind of dynamic you
    just can't find everywhere, ya know? How lucky we are that you so
    generously shared your methodology with us.

    Oh btw, what happens if people from more than just one timezone use the
    site? Hmm, your solution doesn't seem to consider that in the slightest...
    Oh gosh, that makes it sort of... useless, doesn't it? I guess I'm left
    shocked and amazed...




    > --
    > Evertjan.
    > The Netherlands.
    > (Replace all crosses with dots in my emailaddress)
    >
    Mark J. McGinty, Oct 16, 2005
    #3
  4. RICHARD BROMBERG

    Bullschmidt Guest

    Bullschmidt, Oct 17, 2005
    #4
  5. "Mark J. McGinty" <> wrote in message
    news:u$...

    Oops, this:

    > So if accuracy is of extreme importance, you should post both the timezone
    > offset and the time-of-day (UTC) from the client to yourself, convert your
    > server time to UTC, and see if they match, +-15 minutes or so. If not,
    > inform the user that there is a configuration issue.


    should of course read:

    .... post both the timezone offset and the *local* time-of-day from the
    client to yourself, use them to calc UTC, convert your server time to UTC...

    Sorry about that,
    Mark
    Mark J. McGinty, Oct 17, 2005
    #5
  6. Many thanks to almost one and all.

    The response from Evertjan in the Netherlands was useless, Just a small
    pothole in the internet superhighway.


    "Bullschmidt" <> wrote in message
    news:O%...
    > Here's how I like to handle time zones:
    >
    > Classic ASP Design Tips - Time Zones
    > http://www.bullschmidt.com/devtip-timezones.asp
    >
    > Best regards,
    > J. Paul Schmidt, Freelance Web and Database Developer
    > http://www.Bullschmidt.com
    > Access Database Sample, Web Database Sample, ASP Design Tips
    >
    > *** Sent via Developersdex http://www.developersdex.com ***
    RICHARD BROMBERG, Oct 17, 2005
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. vizlab
    Replies:
    3
    Views:
    4,203
    Michael Bar-Sinai
    Oct 17, 2007
  2. ++imanshu
    Replies:
    7
    Views:
    471
    ++imanshu
    Aug 23, 2008
  3. Lucas Nussbaum

    Time::xmlschema returns wrong results

    Lucas Nussbaum, Aug 19, 2005, in forum: Ruby
    Replies:
    1
    Views:
    112
    Tanaka Akira
    Aug 19, 2005
  4. Trans
    Replies:
    2
    Views:
    223
    Trans
    Nov 6, 2005
  5. Srijayanth Sridhar
    Replies:
    19
    Views:
    617
    David A. Black
    Jul 2, 2008
Loading...

Share This Page