您的位置:首页 > Web前端 > JavaScript

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

2007-09-17 17:03 656 查看
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')
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: