为什么时分秒一直为0

tnjun123456 2012-01-14 02:39:07
function formatDate(v){
if(v instanceof Date){
var year = v.getFullYear();
var month = v.getMonth()+1;
var day = v.getDate();
var hour = v.getHours();
var min = v.getMinutes();
var seconds = v.getSeconds();
var ms = v.getMilliseconds();
alert(year+"-"+month+"-"+day+" "+hour+":"+min+":"+seconds+"."+ms);
if(ms > 0){
return year+"-"+month+"-"+day+" "+hour+":"+min+":"+seconds+"."+ms;
}
if(hour>0 || min > 0 || seconds > 0){
return year+"-"+month+"-"+day+" "+hour+":"+min+":"+seconds;
}
return year+"-"+month+"-"+day;
}
return "";
}

为什么上面alert显示的时分秒一直为0??????
...全文
336 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
tnjun123456 2012-01-17
  • 打赏
  • 举报
回复
好吧····谢谢!
yifeng_start 2012-01-16
  • 打赏
  • 举报
回复
不知道,坐等解释,mark一下····
tnjun123456 2012-01-16
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 free_wind22 的回复:]

Web Jan 11 00:00:00 UTC+0800 2012

传进来的就是 0时0分0秒
[/Quote]
我是想知道,怎么样,他传进来的才会不是 0时0分0秒
2012-01-16
  • 打赏
  • 举报
回复
你用datetimebox看看,这个不带时间的吧
2012-01-14
  • 打赏
  • 举报
回复
Web Jan 11 00:00:00 UTC+0800 2012

传进来的就是 0时0分0秒
tnjun123456 2012-01-14
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 free_wind22 的回复:]

function formatDate(v){
alert(v);
...

第一行先alert下看传进来的是什么。
[/Quote]

Web Jan 11:00:00:00 UTC+0800 2012
tnjun123456 2012-01-14
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 free_wind22 的回复:]

function formatDate(v){
alert(v);
...

第一行先alert下看传进来的是什么。
[/Quote]
这个传进来的是
但是我想知道为什么传进来的时分秒都为0
2012-01-14
  • 打赏
  • 举报
回复
function formatDate(v){
alert(v);
...

第一行先alert下看传进来的是什么。
tnjun123456 2012-01-14
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 q2104574 的回复:]

参数问题哦
[/Quote]
小弟刚学easyui不懂·····
tnjun123456 2012-01-14
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 free_wind22 的回复:]

运行结果正常,你传进去的参数是什么?
[/Quote]
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=GBK">
<title>jquery easy ui datebox的使用</title>
<link rel="stylesheet" type="text/css" href="../sources/themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="../sources/themes/icon.css">
<script type="text/javascript" src="../sources/jquery-1.7.1.min.js"></script>
<script type="text/javascript" src="../sources/jquery.easyui.min.js"></script>

<style type="text/css">
</style>
<script type="text/javascript">
function disable(){
$("#inDateBox").datebox("disable","none");
}
function enable(){
$("#inDateBox").datebox("enable");
}
function formatDate(v){
if(v instanceof Date){
var year = v.getFullYear();
var month = v.getMonth()+1;
var day = v.getDate();
var hour = v.getHours();
var min = v.getMinutes();
var seconds = v.getSeconds();
var ms = v.getMilliseconds();
alert(year+"-"+month+"-"+day+" "+hour+":"+min+":"+seconds+"."+ms);
if(ms > 0){
return year+"-"+month+"-"+day+" "+hour+":"+min+":"+seconds+"."+ms;
}
if(hour>0 || min > 0 || seconds > 0){
return year+"-"+month+"-"+day+" "+hour+":"+min+":"+seconds;
}
return year+"-"+month+"-"+day;
}
return "";
}
$(function(){
$("#inDateBox").datebox({
currentText:"今天",
closeText:"关闭",
disabled:false,
required:true,
missingMessage:"必填",
formatter:formatDate
});

$("#testInDateBox1").datebox({
currentText:"今天",
closeText:"关闭",
disabled:false,
required:false,
missingMessage:"必填",
formatter:formatDate
});

$("#testInDateBox2").datebox({
currentText:"今天",
closeText:"关闭",
disabled:true,
required:true,
missingMessage:"必填",
formatter:formatDate
});
});
</script>
</head>
<body>
<h1>DateBox</h1>
<div>
<a href="#" onclick="disable();">disable</a>
<a href="#" onclick="enable();">enable</a>
</div>
<input type="text" id="inDateBox" />
<br/><br/>
<input type="text" id="testInDateBox1" />
<br/><br/>
<input type="text" id="testInDateBox2" />
</body>
</html>
这是完整代码
q2104574 2012-01-14
  • 打赏
  • 举报
回复
参数问题哦
2012-01-14
  • 打赏
  • 举报
回复
运行结果正常,你传进去的参数是什么?

87,921

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧