Convert stored mysql DateTime of UTC datetime stamp into another timezone

Discussion in 'Javascript' started by Justin Voelker, Dec 2, 2008.

  1. Hello everyone:
    I have seen posts like this one a couple times looking through this
    group but I have yet to find a simple, elegant answer and I know there
    must be one. I have a mysql database that has a datetime field in the
    format Y-m-d H:i:s for the UTC time of a given post. If I am in the
    eastern timezone I am currently at -5 hours from UTC so when I make my
    post at 1:00pm eastern time, the time I see dispalyed on the page is
    6:00pm because it is 6:00pm UTC. How can I take that UTC datetime
    stamp and convert it to the correct datetime given a specific php
    timezone such as America/New_York? I know there must be a simple way
    to do this I just haven't been searching the right words or
    something. Please help! Thank you!!!
     
    Justin Voelker, Dec 2, 2008
    #1
    1. Advertisements

  2. Justin Voelker wrote in comp.lang.*javascript*:
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    Use PHP code. (That was easy!)


    PointedEars
     
    Thomas 'PointedEars' Lahn, Dec 2, 2008
    #2
    1. Advertisements

  3. In comp.lang.javascript message <4fd37614-4479-4089-861c-a22a5f0825f5@33
    g2000yqm.googlegroups.com>, Tue, 2 Dec 2008 10:40:09, Justin Voelker
    I am assuming that you want a JavaScript answer, since otherwise you
    should not be asking in a JavaScript group.

    I suppose you are reading a string S of the form "Y/M/D h:m:s" with new
    Date(S), or the individual numbers with new Date(Y, M, D, h, m, s); or
    that toy are displaying a string directly from PHP.

    In the first case, use S + " UTC" or S + " GMT".

    In the second case, use new Date(Date.UTC(Y, M, D, h, m, s)) .

    In the third case, be guided by the answer for the first case.

    See <URL:http://www.merlyn.demon.co.uk/js-dates.htm>.

    Note that the Eastern timezone is not necessarily -5 hours from UTC; it
    can be about ten hours from UTC.

    It's a good idea to read the newsgroup c.l.j and its FAQ. See below.
     
    Dr J R Stockton, Dec 2, 2008
    #3
    1. Advertisements

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.