想要2013-2-29 12:12:12 这种格式
var nowTime = new Date();
var daystr = nowTime.format('YYYY-MM-DD'); 出错
11 回复
Date.prototype.Format = function (fmt) { //author: meizz
var o = {
"M+": this.getMonth() + 1, //月份
"d+": this.getDate(), //日
"h+": this.getHours(), //小时
"m+": this.getMinutes(), //分
"s+": this.getSeconds(), //秒
"q+": Math.floor((this.getMonth() + 3) / 3), //季度
"S": this.getMilliseconds() //毫秒
};
if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
for (var k in o)
if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
return fmt;
} 调用:
var time1 = new Date().Format(“yyyy-MM-dd”); var time2 = new Date().Format(“yyyy-MM-dd HH:mm:ss”);
谢谢
还有个问题,就是字符串拼接 比如:
var daystr=new Date().Format("yyyy-MM-dd HH:mm:ss");
var sql="select top 10 worksite,left(NeedDeal,45) as NeedDeal,UserCoName,gz from [WorkSite] where ToDate>‘"+daystr+"’ and stop=0 order by PDate desc";
错误提示
query: 'select top 10 worksite,left(NeedDeal,45) as NeedDeal,UserCoName,gz from [WorkSite] where ToDate>\'"2013-2-30 17:11"\' and stop=0 order by PDate desc'
变为’"2012-2-30 17:11"’ 要怎么写啊?