Date.prototype.format = function (format) //author: meizz
{
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;
}
function formatTime(val) {
var re = /-?\d+/;
var m = re.exec(val);
var d = new Date(parseInt(m[0]));
// 按【2012-02-13 09:09:09】的格式返回日期
return d.format("yyyy-MM-dd hh:mm:ss");
}
function formatDate(val) {
var re = /-?\d+/;
var m = re.exec(val);
var d = new Date(parseInt(m[0]));
// 按【2012-02-13 09:09:09】的格式返回日期
return d.format("yyyy-MM-dd");
}
相关文章
- 关于使用Ajax请求json数据,@RequestMapping返回中文乱码的几种解决办法
- Spring mvc 返回JSON 在IE 下提示下载 解决办法
- MySQL Unable to convert MySQL date/time value to System.DateTime的解决办法
- TypeError: datetime.datetime(2016, 9, 25, 21, 12, 19, 135649) is not JSON serializable解决办法
- C#调用接口返回json数据中含有双引号 或其他非法字符的解决办法
- MySQL使用DATETIME字段中的DATE返回今天的记录
- ASP.Net Core中设置JSON中DateTime类型的格式化(解决时间返回T格式)
- js 时间转成时间戳对比;My97DatePicker日历控件时间格式;Date.parse Firefox火狐浏览器返回Nan的解决办法
- DateTime怎么返回一个整数代表了从 1970 年 1 月 1 日开始计算到 Date 对象中的时间之间的毫秒数。