Skip to content

Instantly share code, notes, and snippets.

@niyari
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save niyari/9300654 to your computer and use it in GitHub Desktop.
Save niyari/9300654 to your computer and use it in GitHub Desktop.
はてなブログで日付に曜日を付けるやつ (1行版もあります。)
(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;
}
})();
@niyari
Copy link
Author

niyari commented Mar 4, 2014

これは何ですか?: http://psn.hatenablog.jp/entry/2014/03/02/112020
もっと簡単にできませんか?:http://psn.hatenablog.jp/entry/2014/03/30/225710

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment