datatime类型正确格式
yy-mm-dd hh:mm:ss
yy-mm-dd hh:mm:ss
解决方案 »
- 请教各位,能用js判断<embed>标签里的flash文件何时加载完毕么?
- 弹出一个网页,背景颜色变暗的那种是怎么做到的
- 时下最流行的双击处于编辑状态更新数据库的方法
- 数字分页(1,2,3..)的代码
- 如何用javascript关闭由父窗口打开的所有弹出窗口,具体详见文章内容。
- 极度求救 请问jscript 能不能实现下载
- 十万火急!请问那位高手有日期选择框的javascript程序了
- 如何改变一个form的action和method啊!!!!
- 在线等:下面代码中的两个函数为什么不能执行的?
- window.open,怎样正确显示标题
- 我从word里复制一些东西到我的再现编辑器,结果那些内容里有好多看不懂的代码,使我的在线编辑器编辑老是出错,请问怎么解决
- 在IE中屏蔽退格键(Back Space)问题?
var d = new Date();
d = formatDateTime(d,"datetime");
//就可以直接把d的值提交到数据库了.
alert(d);function formatDateTime(date, mode)
{
/*
*--------------- formatDateTime(date, mode) -----------------
*formatDateTime(date, mode)
* 功能:格式化时间的输入出格式.
* 参数:date,时间实例.
* 参数:mode,字符串:"date","time","datetime"
* 返回:时间输出字符串
*--------------- formatDateTime(date, mode) -----------------
*/
function getDateString(date){
var years=date.getFullYear();
var months=date.getMonth()+1;
var days=date.getDate(); if (months<10) months="0"+months;
if (days<10) days="0"+days; return years+"-"+months+"-"+days;
} function getTimeString(date){
var hours=date.getHours();
var minutes=date.getMinutes();
var seconds=date.getSeconds(); if (hours<10) hours="0"+hours;
if (minutes<10) minutes="0"+minutes;
if (seconds<10) seconds="0"+seconds; return hours+":"+minutes+":"+seconds;
} if (typeof(date)=="object" && !isNaN(date)){
if (!mode) mode="datetime";
switch (mode){
case "date":{
return getDateString(date);
break;
}
case "time":{
return getTimeString(date);
break;
}
case "datetime":{
return getDateString(date)+" "+getTimeString(date);
break;
}
default:{
return getDateString(date)+" "+getTimeString(date);
break;
}
}
}
else
return "";
}
</script>