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. Advertising

  2. Re: Convert stored mysql DateTime of UTC datetime stamp into anothertime zone

    Justin Voelker wrote in comp.lang.*javascript*:
    > [...] 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

    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    Use PHP code. (That was easy!)


    PointedEars
    --
    realism: HTML 4.01 Strict
    evangelism: XHTML 1.0 Strict
    madness: XHTML 1.1 as application/xhtml+xml
    -- Bjoern Hoehrmann
     
    Thomas 'PointedEars' Lahn, Dec 2, 2008
    #2
    1. Advertising

  3. Re: Convert stored mysql DateTime of UTC datetime stamp into another time zone

    In comp.lang.javascript message <4fd37614-4479-4089-861c-a22a5f0825f5@33
    g2000yqm.googlegroups.com>, Tue, 2 Dec 2008 10:40:09, Justin Voelker
    <> posted:

    >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!!!


    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.

    --
    (c) John Stockton, nr London UK. ?@merlyn.demon.co.uk IE7 FF2 Op9 Sf3
    news:comp.lang.javascript FAQ <URL:http://www.jibbering.com/faq/index.html>.
    <URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
    <URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
     
    Dr J R Stockton, Dec 2, 2008
    #3
    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. =?Utf-8?B?aGVuaw==?=

    Covert UTC String to UTC Datetime

    =?Utf-8?B?aGVuaw==?=, May 7, 2006, in forum: ASP .Net
    Replies:
    3
    Views:
    18,745
    Egbert Nierop \(MVP for IIS\)
    May 7, 2006
  2. asaf
    Replies:
    3
    Views:
    6,159
    =?ISO-8859-1?Q?Arne_Vajh=F8j?=
    Sep 11, 2006
  3. Mark B
    Replies:
    1
    Views:
    872
    Alexey Smirnov
    Sep 24, 2009
  4. aspineux
    Replies:
    3
    Views:
    281
    aspineux
    Oct 21, 2011
  5. Ami
    Replies:
    5
    Views:
    281
Loading...

Share This Page