对JS中的Date对象扩展日期格式的脚本

javascript February 16 2012


/** * 格式化时间,如:1997- 7- 7 8: 8: 8 @returns {String} */function formatTime() {var year=this.getYear();var month=this.getMonth()+1;var date=this.getDate();var hour=this.getHours();var minute=this.getMinutes();var second=this.getSeconds();return year+ “- “+month+ “- “+date+ “ “+hour+ “: “+minute+ “: “+second;}/** * 格式化日期,如:1997- 7- 7 */function formatDate() {var year=this.getYear();var month=this.getMonth()+1;var date=this.getDate();return year+ “- “+month+ “- “+date;}Date.prototype.formatTime=formatTime;Date.prototype.formatDate=formatDate;

原文链接:http://ichatter.cn/e5-af-b9js-e4-b8-ad-e7-9a-84date-e5-af-b9-e8-b1-a1-e6-89-a9-e5-b1-95-e6-97-a5-e6-9c-9f-e6-a0-bc-e5-bc-8f-e7-9a-84-e8-84-9a-e6-9c-ac.html


欢迎来到阿J小虫的博客

Follow @ichatter on GitHub

最新评论

推荐内容