js 日期处理,json处理

时间:2023-12-10 23:14:50
模块化js :requirejs
http://www.requirejs.cn/ 好用的日期控件:
http://www.bootcss.com/p/bootstrap-datetimepicker/index.htm //日期处理 //js 日期格式化通用方法
Date.prototype.format = function(format){
var o = {
"M+" : this.getMonth()+1, //month
"d+" : this.getDate(), //day
"h+" : this.getHours(), //hour
"m+" : this.getMinutes(), //minute
"s+" : this.getSeconds(), //second
"q+" : Math.floor((this.getMonth()+3)/3), //quarter
"S" : this.getMilliseconds() //millisecond
}
if(/(y+)/.test(format)) {
format = format.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length));
} for(var k in o) {
if(new RegExp("("+ k +")").test(format)) {
format = format.replace(RegExp.$1, RegExp.$1.length==1 ? o[k] : ("00"+ o[k]).substr((""+ o[k]).length));
}
} return format;
} var now = new Date();
// js 日期处理
var nowadd = now.setFullYear(now.getFullYear()+2);
var d2=new Date(nowadd)
var nowStr = d2.format("yyyy-MM-dd");
$('#userTime').val(nowStr);
//表单标准化成json

function standJsonByObj(obj){

    var o = {};
var a = $(obj).serializeArray();
$.each(a, function() {
if (o[this.name] !== undefined) {
if (!o[this.name].push) {
o[this.name] = [o[this.name]];
}
o[this.name].push(this.value || '');
} else {
o[this.name] = this.value || '';
}
});
return o;
};