Date.prototype.setISO8601 = function(string) {
    //...http://delete.me.uk/2005/03/iso8601.html
    //sample: '1997-07-16T19:20+01:00'
    //For valid ISO8601 patters see:
    //...http://www.w3.org/TR/NOTE-datetime    
    //INGO: was not handling milliseconds OK, rewritten using the RegExp provided by Grauw as a comment to above (thanks!)
    //alterted Grauw's regexp for Z detecion from (?:Z| to (?:([Z]) to be able to track the Z in the match array
    //original:  /(\d\d\d\d)(?:-?(\d\d)(?:-?(\d\d)(?:[T ](\d\d)(?::?(\d\d)(?::?(\d\d)(?:\.(\d+))?)?)?(?:Z|(?:([-+])(\d\d)(?::?(\d\d))?)?)?)?)?)?/;	
    var regexp = /(\d\d\d\d)(?:-?(\d\d)(?:-?(\d\d)(?:[T ](\d\d)(?::?(\d\d)(?::?(\d\d)(?:\.(\d+))?)?)?(?:([Z])|(?:([-+])(\d\d)(?::?(\d\d))?)?)?)?)?)?/;

    if (string != "") {
        var d = string.match(new RegExp(regexp));

        var utc = false;
        var localTime = false;
        var localOffset = 0;
        var offset = 0;

        var date = new Date(d[1], 0, 1);

        if (d[2]) { date.setMonth(d[2] - 1); }
        if (d[3]) { date.setDate(d[3]); }
        if (d[4]) { date.setHours(d[4]); }
        if (d[5]) { date.setMinutes(d[5]); }
        if (d[6]) { date.setSeconds(d[6]); }
        if (d[7]) { date.setMilliseconds(Number("0." + d[7]) * 1000); }
        if (d[8] == 'Z') {
            utc = true;
            offset = date.getTimezoneOffset();
        } else if (d[9]) {
            localTime = true;
            localOffset = (Number(d[10]) * 60) + Number(d[11]);
            localOffset *= ((d[9] == '-') ? 1 : -1);
            offset = localOffset - date.getTimezoneOffset();
        }
        time = (Number(date) + (offset * 60 * 1000));
        this.setTime(Number(time));
        //to make the client aware of what the input was like
        this.ISO8601asUnspecified = !(utc || localTime);
        this.ISO8601asUTC = utc;
        this.ISO8601asLocalTime = localTime;
        this.ISO8601LocalTimeOffset = localOffset; //to set this date to same local time as input use:   this.setISO8601asLocalTime()
    }
} 
 
Date.prototype.setISO8601asLocalTime = function(){
    //...we want to convert the time to the ISO8601 provided local time 
    if (this.ISO8601asUnspecified){
        //...was set without any timezone, we have no clue of any other timezone
    }
    else if(this.ISO8601asUTC){
       //...was set as UTC, we still have no clue of any other timezone
    }
    else if (this.ISO8601asLocalTime){
        //...was set using local timezone, adjust acoording to this timezone 
        this.setMinutes(this.getMinutes() +  this.getTimezoneOffset() - this.ISO8601LocalTimeOffset);
    }   
}

Date.prototype.getISO8601 = function(){    
    var str;
    var num;
    
    //...'2008-01-01T10:20:30Z'(UTC time)
    //... http://www.w3schools.com/jsref/jsref_obj_date.asp
    //... http://www.w3.org/TR/NOTE-datetime
    
    num = this.getUTCFullYear();
    str = '' + num;    
    num = this.getUTCMonth() + 1;
    str += '-' + (num >= 10 ? num : '0' + num);    
    num = this.getUTCDate();
    str += '-' + (num >= 10 ? num : '0' + num);    
    
    num = this.getUTCHours() + 1;
    str += ' ' + (num >= 10 ? num : '0' + num);
    num = this.getUTCMinutes();
    str += ':' + (num >= 10 ? num : '0' + num);
    num = this.getUTCSeconds();
    str += ':' + (num >= 10 ? num : '0' + num);
    str += 'Z';
    
//    num = this.getTimezoneOffset();        
//    var negative = num < 0;
//    if (negative)
//      num = -num;      
//    var h = parseInt(num/60);        
//    var m = (num/60 - h)*60;        
//    h = '' + h >= 10 ? h : '0' + h;
//    m = '' + m >= 10 ? m : '0' + m;
//    if (negative)
//        str += '+' + h + ':' + m;
//    else
//        str += '-' + h + ':' + m;        
    return str;
}
