假如日期格式只有1种:
年-月-日 小时:分钟:秒function MyCalendar()
{
this.year=null;
this.month=null;
this.day=null;
this.hour=null;
this.minute=null;
this.second=null;
}如何最有效率的把它们提取到MyCalendar中。
年-月-日 小时:分钟:秒function MyCalendar()
{
this.year=null;
this.month=null;
this.day=null;
this.hour=null;
this.minute=null;
this.second=null;
}如何最有效率的把它们提取到MyCalendar中。
解决方案 »
- 其实是AS的最小生成树问题,不过没找到相应模块,所以发这里.谁帮忙看看有问题么?
- onchange事件触发问题
- 请教---JS截取字符串---谢谢大家
- 关于Ext的TabPanel的问题
- <td onselectstart="javascript:selection.empty();"><input type="text" /></td>怎么使input的选择保持有效?
- js聚焦 看起来挺简单的.
- 怎样在javascript中直接设置好打印方式为横向或纵向?急
- 用javascript 如何取得select 的文本值呢
- 如何使指定的frame聚焦
- 哪位高手解释一下这段代码?谢谢!
- JavaScript 如何去掉下载或打开的安全提示??
- 我的这段代码 为什么不能执行????
{
var dt=new Date();
alert(dt.getYear()+"年 "+dt.getMonth()+"月 "+dt.getDay()+"日 "+dt.getHours()+":"+dt.getMinutes()+":"+dt.getSeconds());
}
getCurTime();
</script>
{
var dt=new Date();
alert(dt.getYear()+" - "+dt.getMonth()+" - "+dt.getDay()+" "+dt.getHours()+":"+dt.getMinutes()+":"+dt.getSeconds());
}
getCurTime();
</script>
{
var dt=new Date();
alert(dt.getYear()+" - "+(dt.getMonth()+1)+" - "+dt.getDate()+" "+dt.getHours()+":"+dt.getMinutes()+":"+dt.getSeconds());
}
getCurTime();
</script>
var b=str.match(/\d+(?!\d)/g);
this.year=b[0];
this.month=b[1];
this.day=b[2];
this.hour=b[3];
this.minute=b[4];
this.second=b[5];
alert(this.year+"-"+this.month+"-"+this.day+" "+this.hour+":"+this.minute+":"+this.second)
<head>
<title>用正则</title>
<script type="text/javascript">
var date = '2009年05月11日 小时:10分钟:24秒:45 ';
function MyCalendar(_date)
{
var reg = /\d+/g;
var timeInfo = _date.match(reg);
this.year = timeInfo[0];
this.month = timeInfo[1];
this.day = timeInfo[2];
this.hour = timeInfo[3];
this.minute = timeInfo[4];
this.second = timeInfo[5];
}
MyCalendar(date);
/*测试用函数
var mc = new MyCalendar(date);
alert('year: ' + mc.year + '. month: ' + mc.month + ', day: ' + mc.day + ', hour: ' + mc.hour + ', mimute: ' + mc.minute + ', second: ' + mc.second);
*/
</script>
</head>
<body></body>
</html>
function MyCalendar(str)
{
//日期时间的格式 : YYYY-MM-DD hh:mm:ss ; 返回时间的各个部分 ;
var dt=str;
var year=null;
var month=null;
var day=null;
var hour=null;
var minute=null;
var second=null;
year=dt.split("-")[0];
month=dt.split("-")[1];
day=(dt.split("-")[2]).substr(0,2);
hour=dt.split(" ")[1].split(":")[0];
minute=dt.split(" ")[1].split(":")[1];
second=dt.split(" ")[1].split(":")[2];
var r=year+"-"+month+"-"+day+" "+hour+":"+minute+":"+second;
alert(r);
} //测试,这里你可以从文本框中得到输入的日期时间数据
MyCalendar("2009-5-11 10:40:23");
</script>