怎么将这种类型
Mon Sep 15 00:00:00 CEST 2008
的日期转化为
2008-10-15
Mon Sep 15 00:00:00 CEST 2008
的日期转化为
2008-10-15
解决方案 »
- 这个代码 具体是什么意思!
- 时间:小时+分钟的正则表达式是什么?
- 有没有JavaScript: The Definitive Guide, 5th Edition 中文版的电子书?
- 可否在某网页中点击某个链接点弹出CHM(Windows帮助)文件?
- 求助:如何用javascript实现类似网易,新浪等网站免费邮箱中增加附件的功能?(急!!!)
- 连续按键卡顿
- 使用fso的GetSpecialFolder方法获得了C:\DOCUME~1...这样的路径,求长路径名获得方法
- 我想一个提交事件可以解决两个sub
- 用javascript调用本地函数或.exe如何关机??(答完给分)
- 如何获取网页中选择的文本?
- 求文字滚动JS代码
- 写一个简单javascript菜单,百分送上
{//调整时间显示格式2007-01-01 12:00:00
return D.getFullYear() + "-" + (D.getMonth() + 1) + "-" + D.getDate() + " " + D.getHours() + ":" + D.getMinutes() + ":" + D.getSeconds();
}
alert("转化前:" + new Date());
alert("转化后:" + formatDate(new Date()));
if(!Date.prototype.format){//日期格式化
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 str="Mon Sep 15 00:00:00 CEST 2008 ";
var d=new Date();
alert(d.format("yyyy-MM-dd"));
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<script type="text/javascript">
window.onload = function(){
var dd = 'Mon Sep 15 00:00:00 CEST 2008';
var arr = dd.split(' ');
ri = '';
year = '';
for(var i = 0; i < arr.length; i++){
if(arr[i].length == 2 && !isNaN(arr[i])){
ri = arr[i];
}else if(arr[i].length == 4 && !isNaN(arr[i])){
year = arr[i];
}
}
alert(year + '-' + ri);
}
</script>
</head><body>
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<script type="text/javascript">
window.onload = function(){
var dd = 'Mon Sep 15 00:00:00 CEST 2008';
var arr = dd.split(' ');
var ri = '';
var year = '';
var month = '';
for(var i = 0; i < arr.length; i++){
if(arr[i].length == 2 && !isNaN(arr[i])){
ri = arr[i];
}else if(arr[i].length == 4 && !isNaN(arr[i])){
year = arr[i];
}
switch(arr[i]){
case 'Sep':month = 10;break;
}
}
alert(year + '-' + month + '-' + ri);
}
</script>
</head><body>
</body>
</html>
不行将中间的替换掉
改下:var str="Mon Sep 15 00:00:00 CEST 2008";
str=str.replace("CEST","");
var d=new Date(str);
alert(d.format("yyyy-MM-dd"));lz看我倒数第三个帖子