💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
### 格式化日期 ```javascript // <summary> // 格式化显示日期时间 // </summary> // <param name="x">待显示的日期时间,例如new Date()</param> // <param name="y">需要显示的格式,例如yyyy-MM-dd hh:mm:ss</param> function date2str(x,y) { var z ={y:x.getFullYear(),M:x.getMonth()+1,d:x.getDate(),h:x.getHours(),m:x.getMinutes(),s:x.getSeconds()}; return y.replace(/(y+|M+|d+|h+|m+|s+)/g,function(v) {return ((v.length>1?"0":"")+eval('z.'+v.slice(-1))).slice(-(v.length>2?v.length:2))}); } alert(date2str(new Date(),"yy-M-d h:m:s")); alert(date2str(new Date(),"yyyy-MM-d h:m:s")); ``` > 来源:[ javascript两行代码按指定格式输出日期时间](http://blog.csdn.net/aasum/article/details/48816293) --- ```javascript /* *时间格式化 *例子:time = new Date().Format("yyyy-MM-dd hh:mm:ss"); */ Date.prototype.Format = function (fmt) { 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; } ``` > 来源 [特殊字符转义&时间格式化&获取URL参数](http://www.cnblogs.com/duanhuajian/p/4485106.html)