---sql cast(A.SupportDate as datetime) As SupportDate rs.getTimestamp("SupportDate") ---Format SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd"); sdf.format(SupportDate)
但是在数据库里读出来的时候就是java.sql.date,然后通过转换变成java.util.date直接显示在json里面就上面的代码,我的javabean里面是设置date属性的你前面是直接把数据库取出来的值放入json里面,但是你在给json的"time"赋值的时候,可以先用SimpleDateFormat将数据从date转换成“yy-MM-dd”字符串格式,这和你的javabean并不冲突 OK了,因为我把它转成了java.util.date了,config.registerJsonValueProcessor(java.util.Date.class, new DateJsonValueProcessor("yyyy-MM-dd"));
在前台就去这个get方法的值
例如字段是date 有一个getDate的方法,再写一个getDateStr
前台就直接去dateStr就好了!
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;
}//根据tpi_birth的time值实例一个date对象
var d = new Date(parseInt(tpi_birth.time));
//将日期格式化,d_str就是你想要的值
var d_str = new Date().Format("yyyy-MM-dd");
JsonConfig config = new JsonConfig();
config.setIgnoreDefaultExcludes(false);
config.registerJsonValueProcessor(java.sql.Date.class, new DateJsonValueProcessor("yyyy-MM-dd"));
JSONArray resultArray = JSONArray.fromObject(list,config);
这样设置再转换,sql.Date的日期类型就变成你要的字符串了。
详细点
cast(A.SupportDate as datetime) As SupportDate
rs.getTimestamp("SupportDate")
---Format
SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd");
sdf.format(SupportDate)
OK了,因为我把它转成了java.util.date了,config.registerJsonValueProcessor(java.util.Date.class, new DateJsonValueProcessor("yyyy-MM-dd"));
$(#tb_1).datagrid('loaddata', json)
是这样的吗?