CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Apr 2005
    Posts
    172

    Convert from UTC Time zone to Local TIme Zone

    Hello,

    I am working on a web application which stores all Dates in GMT time zone.

    When I display the dates to the user I need to display them in their local time zone.

    So for example in my DB I have a date 08.07.2009 14:45:23 and this is GMT time

    When the user views the page I need it to display 08.07.2009 10:45:23 .

    HOw can I do that with Javascript function.

    I have done some research but no luck

    here is the function so far:

    Code:
    function ToLocalTimeZone(gmt)
        {
         
            var gmtDate = new Date(gmt);
           }
    according to what I'veread that shouhld automatically convert it to the local time zone on the client but it does not.

    I've also tried using var localDate = gmtDate.toLocaleString();

    but I still get the original date only the format has changed a bit.

    Thank you very much in advance

    Susan

  2. #2
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,284

    Re: Convert from UTC Time zone to Local TIme Zone

    To convert a date to UTC :
    Code:
    mydateObject.toUTCString()
    To convert to GMT :
    Code:
    mydateObject.toGMTString()

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured