Last active
August 29, 2015 14:01
-
-
Save msh9/9dd264e833add51c038f to your computer and use it in GitHub Desktop.
Processing dates
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//N.B. Use Steven Levithan's date formatter for richer string output options | |
//http://blog.stevenlevithan.com/archives/date-time-format | |
if (window.addEventListener) // W3C standard | |
{ | |
window.addEventListener('load', function() { | |
var timeElements = document.getElementsByClassName('make-time'); | |
for (var i = 0; i < timeElements.length; i++) { | |
var dateStr = timeElements[i].getAttribute('data-time'); | |
if (dateStr) { | |
var utcDate = new Date(dateStr); | |
timeElements[i].textContent = utcDate.toTimeString(); | |
} | |
} | |
}, false); // NB **not** 'onload' | |
//include the following if you need to support below IE9 | |
} else if (window.attachEvent) { | |
window.attachEvent('onload', function () { | |
var timeElements = document.getElementsByClassName('make-time'); | |
for (var i = 0; i < timeElements.length; i++) { | |
var dataStr = timeElements[i].getAttribute('data-time'); | |
if (dateStr) { | |
var utcDate = new Date(dateStr); | |
timeElements[i].textContent = utcDate.toTimeString(); | |
} | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment