js 格式化时间 现在我把一个日期变量输出后显示Tue Sep 15 09:42:19 UTC+0800 2009 请问我用什么方法格式化成(2009-9-15)大家帮忙看看,谢谢了 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 <script>var d = new Date("Tue Sep 15 09:42:19 UTC+0800 2009");alert(d.getFullYear()+"-"+(d.getMonth()+1)+"-"+d.getDate());</script> var d = new Date("Tue Sep 15 09:42:19 UTC+0800 2009");alert(d.toLocaleDateString()) alert(new Date().toLocaleDateString().replace('年','-').replace('月','-').replace('日','')); var t=new Date(),y,n,d,h,m,s,a=new Array("星期日","星期一","星期二","星期三","星期四","星期五","星期六"); y=t.getFullYear(); n=t.getMonth()+1; if(n<10)n="0"+n; d=t.getDate(); if(d<10)d="0"+d; h=t.getHours(); if(h<10)h="0"+h; m=t.getMinutes(); if(m<10)m="0"+m; s=t.getSeconds(); if(s<10)s="0"+s; t=y+"-"+n+"-"+d+" "+h+":"+m+":"+s+" "+a[t.getUTCDay()]; alert(t); var t=new Date();alert(t.getFullYear()+"-"+(t.getMonth()+1)+"-"+t.getDate()); 给Date对象加一个格式化方法<script>Date.prototype.format = function(format) { var o = { "M+" : this.getMonth()+1, //month "d+" : this.getDate(), //day "h+" : this.getHours(), //hour "m+" : this.getMinutes(), //minute "s+" : this.getSeconds(), //second "q+" : Math.floor((this.getMonth()+3)/3), //quarter "S" : this.getMilliseconds() //millisecond } if(/(y+)/.test(format)){ format=format.replace(RegExp.$1,(this.getFullYear()+"").substr(4 - RegExp.$1.length)); } for(var k in o){ if(new RegExp("("+ k +")").test(format)){ format = format.replace(RegExp.$1,RegExp.$1.length==1 ? o[k] : ("00"+ o[k]).substr((""+ o[k]).length)); } } return format; } var d = new Date() ; alert(d.format("yyyy")) ; //年 alert(d.format("MM")) ; //月 alert(d.format("dd")) ; //日 alert(d.format("qq")) ; //季度 alert(d.format("yyyy-MM-dd")) ; //年月日</script> extjs 问题 在aspx中如何提取js编辑器里的内容 [新手提问]如何用JS从文本读取字符串? 字符串和int加 Safari预览器兼容问题,请高人指点,谢谢了。(有例子的帮我分析一下) javascript语法小问题????在线等待??? 如何在子窗口添加记录而直接在父窗口上加一条记录 新~定时关闭窗口! 代码有问题 怎么可以控制当前打开的网页的大小,还有不要显示工具栏,状态栏等 webwork中,打印预览框架frame中一个框架中的内容,怎么实现? 关于jquery 的加载问题
var d = new Date("Tue Sep 15 09:42:19 UTC+0800 2009");
alert(d.getFullYear()+"-"+(d.getMonth()+1)+"-"+d.getDate());
</script>
var d = new Date("Tue Sep 15 09:42:19 UTC+0800 2009");
alert(d.toLocaleDateString())
alert(new Date().toLocaleDateString().replace('年','-').replace('月','-').replace('日',''));
y=t.getFullYear();
n=t.getMonth()+1;
if(n<10)n="0"+n;
d=t.getDate();
if(d<10)d="0"+d;
h=t.getHours();
if(h<10)h="0"+h;
m=t.getMinutes();
if(m<10)m="0"+m;
s=t.getSeconds();
if(s<10)s="0"+s;
t=y+"-"+n+"-"+d+" "+h+":"+m+":"+s+" "+a[t.getUTCDay()];
alert(t);
alert(t.getFullYear()+"-"+(t.getMonth()+1)+"-"+t.getDate());
Date.prototype.format = function(format)
{
var o =
{
"M+" : this.getMonth()+1, //month
"d+" : this.getDate(), //day
"h+" : this.getHours(), //hour
"m+" : this.getMinutes(), //minute
"s+" : this.getSeconds(), //second
"q+" : Math.floor((this.getMonth()+3)/3), //quarter
"S" : this.getMilliseconds() //millisecond
}
if(/(y+)/.test(format)){
format=format.replace(RegExp.$1,(this.getFullYear()+"").substr(4 - RegExp.$1.length));
}
for(var k in o){
if(new RegExp("("+ k +")").test(format)){
format = format.replace(RegExp.$1,RegExp.$1.length==1 ? o[k] : ("00"+ o[k]).substr((""+ o[k]).length));
}
}
return format;
}
var d = new Date() ;
alert(d.format("yyyy")) ; //年
alert(d.format("MM")) ; //月
alert(d.format("dd")) ; //日
alert(d.format("qq")) ; //季度
alert(d.format("yyyy-MM-dd")) ; //年月日
</script>