javascript toISOString() ignores timezone offset [duplicate]

I am trying to convert Twitter datetime to a local iso-string (for prettyDate) now for 2 days. I’m just not getting the local time right..

im using the following function:

function getLocalISOTime(twDate) {
    var d = new Date(twDate);
    var utcd = Date.UTC(d.getFullYear(), d.getMonth(), d.getDate(), d.getHours(),
        d.getMinutes(), d.getSeconds(), d.getMilliseconds());

    // obtain local UTC offset and convert to msec
    localOffset = d.getTimezoneOffset() * 60000;
    var newdate = new Date(utcd + localOffset);
    return newdate.toISOString().replace(".000", "");
}

in newdate everything is ok but the toISOString() throws it back to the original time again…
Can anybody help me get the local time in iso from the Twitterdate formatted as:
Thu, 31 May 2012 08:33:41 +0000

7 Answers
7

Leave a Comment