JavaScript 日期转化 怎么将这种类型Mon Sep 15 00:00:00 CEST 2008的日期转化为 2008-10-15 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 function formatDate(D){//调整时间显示格式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看我倒数第三个帖子 求jquery 高手帮忙看看我的代码 请教 ExtJs 调用 Web service 如何传递 Soap Header ? 音乐连续播放并同步歌词 求一个下拉菜单的解决方法,在线等。 关于页面来路的判断 问大家一个JS问题!判断2个字符串格式是否相同! 如何动态获取 table 中 td 所在行 和列 为已经序列化的表单批量添加input 提问!我要屏蔽";"怎么做?? 高手帮忙看看! 求文字滚动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看我倒数第三个帖子