jquery 格式化系统时间
2016-04-25 10:20
525 查看
Date.prototype.Format = function (fmt) { //javascript时间日期函数
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 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"); //获取日期,格式: 年-月-日 时-分-秒
相关文章推荐
- jquery跨域问题
- 解决jquery与zepto等其它库冲突兼容的问题
- PHP语言 -- jquery
- jquery学习02(效果)
- 简易的输入框字数计数 Jquery组件
- 把DOM对象转换为jQuery对象
- 很实用的jQuery事件 - toggle() 方法
- jQuery.extend 函数详解
- jquery 语法
- jquery.fn jquery.extend jquery.fn.extend
- jquery选择器
- jquery的动态绑定on()方法
- jQuery 遍历
- jquery
- jquery学习
- jQuery验证
- 从零开始学_JavaScript_系列(12)——jquery<2>(高度自适应,哈希地址及检测,单页面技术)
- 常使用的10个jQuery代码片段
- jQuery判断select选中
- jQuery基本操作