title: Put the knife down and take a green herb, dude. |
descrip: One feller's views on the state of everyday computer science & its application (and now, OTHER STUFF) who isn't rich enough to shell out for www.myfreakinfirst-andlast-name.com Using 89% of the same design the blog had in 2001. |
FOR ENTERTAINMENT PURPOSES ONLY!!!
Back-up your data and, when you bike, always wear white. As an Amazon Associate, I earn from qualifying purchases. Affiliate links in green. |
|
Tuesday, March 12, 2013 | |
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... http://jsfiddle.net/rufwork/8Mc8Y/ /*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.
// http://tinyurl.com/d5vzqj9
// (https://developer.mozilla.org/en-US/docs/JavaScript/Reference/
// 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>");
document.write("<br>");
milliLocal = getLocalDate('2013-03-01');
document.write(milliLocal + "<br>");
document.write(new Date(milliLocal) + "<br>");
Labels: dates, javascript posted by ruffin at 3/12/2013 02:39:00 PM |
|
| |
MarkUpDown is the best Markdown editor for professionals on Windows 10. It includes two-pane live preview, in-app uploads to imgur for image hosting, and MultiMarkdown table support. Features you won't find anywhere else include...
You've wasted more than $15 of your time looking for a great Markdown editor. Stop looking. MarkUpDown is the app you're looking for. Learn more or head over to the 'Store now! |
![]() |
|
|