Category
show
전체 (775)
웹표준, 웹접근성™ (5)
웹프로그래밍™ (360)
웹기획™ (0)
웹디자인™ (5)
서버™ (32)
데이터베이스™ (43)
개발자료 (9)
트랜드 (60)
Study English (2)
블루비 (70)
오피스 다이어리 (19)
Textcube (2)
이슈 (20)
컴퓨터 악세사리 (18)
엔터테인먼트 (24)
좋은글 (73)
재테크 (1)
이벤트 (4)

[JavaScript] beautyDate , beautyDate : function

웹프로그래밍™/jQuery, Javascript 2008/01/30 09:30 by 블루비 Total 731 : Today 3 : Yesterday 0
John Resig's prettyDate()
- http://ejohn.org/blog/javascript-pretty-date/

Mixed's beautyDate()
- http://mixed.tistory.com/194


/**
 * JavaScript  beautyDate
 * 
 * @author mixed <mailto:i . nevalose (at) gmail . com>
 * @license GNU
 * @blog http://mixed.tistory.com/
 * 
 * @param {Date} date
 * @param {Object} customOption
 * 
 * @return {String} beautyDate
 */
function beautyDate(date,customOption){
	if(arguments.length<1||date.constructor != Date){
		return false;
	}
	var options = {
		format		:"{yyyy}/{mm}/{0d} {0h}:{0i}",
		monthFormat :["01","02","03","04","05","06","07","08","09","10","11","12"],
		weekFormat	:["Mon","Tue","Wed","Thu","Fri","Sat","Sun"],
		ampmFormat	:["am","pm"]
	}
	customOption = customOption||{};
	for(var i in customOption){
		options[i] = customOption[i];
	}
	options["rowData"] = [date.getFullYear()+"",
						  date.getMonth(),
						  date.getDate(),
						  date.getDay(),
						  date.getHours()<12?0:1,
						  date.getHours(),
						  date.getMinutes(),
						  date.getSeconds()];
	return options.format.replace(/\{([^{}]*)\}/g,function(type){
		var coptions = options;

		function addZero(num){
			return (num>=10)?num:"0"+num;
		}
		function twelveNotation(num){
			return (num>12)?num-12:num;
		}
		var rowData 	= coptions.rowData;
		var monthFormat = coptions.monthFormat;
		var weekFormat  = coptions.weekFormat;
		var ampmFormat  = coptions.ampmFormat;
		
		return type=="{yyyy}"&&rowData[0]||
			   type=="{yy}"&&rowData[0].slice(2,4)||
			   type=="{mm}"&&monthFormat[rowData[1]]||
			   type=="{dd}"&&rowData[2]||
			   type=="{0d}"&&addZero(rowData[2])||
			   type=="{ww}"&&weekFormat[rowData[3]-1]||
			   type=="{ap}"&&mFormat[rowData[4]]||
			   type=="{hh}"&&twelveNotation(rowData[5])||
			   type=="{HH}"&&rowData[5]||
			   type=="{0h}"&&addZero(twelveNotation(rowData[5]))||
			   type=="{0H}"&&addZero(rowData[5])||
			   type=="{ii}"&&addZero(rowData[6])||
			   type=="{0i}"&&addZero(rowData[6])||
			   type=="{ss}"&&rowData[7]||
			   type=="{0s}"&&addZero(rowData[7])||"'"+type+":undefined type'";

	});
}

2008/01/30 09:30 2008/01/30 09:30

TRACKBACK :: http://blueb.net/blog/trackback/1078

Leave a Comment
[로그인][오픈아이디란?]
1  ... 204 205 206 207 208 209 210 211 212  ... 775 

달력

«   2008/11   »
            1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30