There's got to be an easier, built-in way to instantiate a local date in JavaScript, right? I understand that timezones are a pain, and I see how UTC is a good way to make date instantiation easier from the browser's point of view, but, um...
/*jslint evil:true*/
/*global document*/
function getLocalDate(strDateRepresentation) {
    var dteTemp, milliUtc, milliOffset;

    dteTemp = new Date(strDateRepresentation);
    milliUtc = dteTemp.getTime();
    milliOffset = 1000 * 60 * dteTemp.getTimezoneOffset();    
    // has to be for THIS date or calc could be off -- EST vs. EDT, eg.
    // (
    //          Global_Objects/Date/getTimezoneOffset)
    // "Daylight saving time prevents this value from being a constant 
    //          even for a given locale"

    return milliUtc + milliOffset;

var milliLocal = getLocalDate('2011-01-01');
document.write(milliLocal + "<br>");
document.write(new Date(milliLocal) + "<br>");


milliLocal = getLocalDate('2013-03-01');
document.write(milliLocal + "<br>");
document.write(new Date(milliLocal) + "<br>");

Labels: ,