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"); //获取日期,格式: 年-月-日 时-分-秒
相关文章
- 12-28通过sntp同步系统时间
- 12-28EBS 系统当前完成请求时间监测
- 12-28分布式系统理论基础 - 时间、时钟和事件顺序
- 12-28分布式系统内的时间,时钟和事件顺序
- 12-28Hutool中DateUtil常用方法(格式化日期Date2Str、Str2Date、获取一天的开始时间和结束时间、日期时间差)
- 12-28thymeleaf时间格式化
- 12-28【tmos】使用joda-time来个格式化时间
- 12-28jquery时间委托详解
- 12-28windows系统下向NTP服务器请求时间代码 C语言,vs2010,windows,socket,udp
- 12-28Android 系统开机时间优化