现在的位置: 首页 > 综合 > 正文

javascript:以前写的日期格式化类DateFormat,源码,js少这个有时候还是不方便

2013年10月13日 ⁄ 综合 ⁄ 共 772字 ⁄ 字号 评论关闭

var DateFormat=function(date){
 //implementation
 var format=function(str){
  str=str.replace(/yyyy/g,date.getFullYear());
  str=str.replace(/yy/g,date.getFullYear().toString().slice(2));
  str=str.replace(/mm/g,date.getMonth()+1);
  str=str.replace(/dd/g,date.getDate());
  str=str.replace(/wk/g,date.getDay());
  str=str.replace(/hh/g,date.getHours());
  str=str.replace(/mi/g,date.getMinutes());
  str=str.replace(/ss/g,date.getSeconds());
  str=str.replace(/ms/g,date.getMilliseconds());
  return str;}
 var valueOf=function(){}
 var toString=function(){
  return date.toLocaleString();}
 //constructor
 date=new Date(date);
 if(!date||date=="NaN")
  date=new Date();
 //inteface
 this.format=format;
 this.valueOf=valueOf;
 this.toString=toString;}

使用:
xxx.value=new DateFormat().format('yy/dd/mm wk') 

【上篇】
【下篇】

抱歉!评论已关闭.