はてなブログで日付に曜日を付けるやつ (1行版もあります。)
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
(function(){ | |
datetimeEle = document.querySelectorAll('.date [datetime]'); | |
for (var i = 0; i < datetimeEle.length; i++){ | |
datetimeEle[i].appendChild(DateToWeek(datetimeEle[i].getAttribute("datetime"))); | |
} | |
function DateToWeek(day){ | |
if(typeof day === "undefined"){return ""} | |
//day = day.substr(0,10); | |
var d = new Date(day); | |
if(typeof d === "undefined" || isNaN( d ) ){return ""} | |
var w = ["Sun","Mon","Tue","Wed","Thu","Fri","Sat"]; | |
/* | |
var w = ["日","月","火","水","木","金","土"]; | |
*/ | |
var el = document.createElement("span"); | |
var str = document.createTextNode(w[d.getDay()]); | |
el.setAttribute("class", "date-week date-week-" + str.data); | |
el.appendChild(str); | |
return el; | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
これは何ですか?: http://psn.hatenablog.jp/entry/2014/03/02/112020
もっと簡単にできませんか?:http://psn.hatenablog.jp/entry/2014/03/30/225710