关于日期格式规范的问题。急! 如果你想实现这样的功能,你得事先考虑所有可能的输入情况,然后分别用replace()把它替换成你需要的格式。用正则表达式来匹配,这样不同的输入情况会被分别匹配。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 <script>function formatdatetime(str){var d=new Date(str.replace(/-/,"/"))var m=d.getMonth()<9?"0"+(d.getMonth()+1):(d.getMonth()+1)return d.getFullYear()+"-"+m+"-"+(d.getDate()<10?"0":"")+d.getDate();}ret=formatdatetime("2002-5-2")alert(ret)ret=formatdatetime("2002-5-14")alert(ret)ret=formatdatetime("2002-11-14")alert(ret)</script> 或者<script>function formatdatetime(str){var d=new Date(str.replace(/-/,"/"))var m=String((d.getMonth()+1)/100).split(".")[1]return d.getFullYear()+"-"+m+"-"+String(d.getDate()/100).split(".")[1];}ret=formatdatetime("2002-5-2")alert(ret)ret=formatdatetime("2002-5-14")alert(ret)ret=formatdatetime("2002-11-14")alert(ret)</script> 求1兼容性较好的(小时:分钟) 时间选择控件 怎么在一个JS中引用其他JS文件 js读取xml内容,并以图片显示内容。? 关于JS自动计算,如果成功可加分 限制字符串长度的问题 extjs4中的flex属性是什么意思呢,有图请进 我想修改class为TR的<tr>对象中的所有<td>对象的样式,能不能页通过添加CSS实现呢? 我想知道这个效果是怎么实现的? 关于window.open()的一个小问题,在线等待 高手。如何以打开页面就是chormless窗口 ie6运行正常,ie5却不正常! 如何用JAVASCRIPT语句查看页面中是否有某一对象,例如是否有名为BUTTON1的按钮在页面中存在
function formatdatetime(str){
var d=new Date(str.replace(/-/,"/"))
var m=d.getMonth()<9?"0"+(d.getMonth()+1):(d.getMonth()+1)
return d.getFullYear()+"-"+m+"-"+(d.getDate()<10?"0":"")+d.getDate();
}
ret=formatdatetime("2002-5-2")
alert(ret)
ret=formatdatetime("2002-5-14")
alert(ret)
ret=formatdatetime("2002-11-14")
alert(ret)
</script>
<script>
function formatdatetime(str){
var d=new Date(str.replace(/-/,"/"))
var m=String((d.getMonth()+1)/100).split(".")[1]
return d.getFullYear()+"-"+m+"-"+String(d.getDate()/100).split(".")[1];
}
ret=formatdatetime("2002-5-2")
alert(ret)
ret=formatdatetime("2002-5-14")
alert(ret)
ret=formatdatetime("2002-11-14")
alert(ret)
</script>