JS Date.Format
  TEZNKK3IfmPf 2023年11月14日 15 0
js
// 对Date的扩展,将 Date 转化为指定格式的String   
// 月(M)、日(d)、小时(h)、分(m)、秒(s)、季度(q) 可以用 1-2 个占位符,
// 年(y)可以用 1-4 个占位符,毫秒(S)只能用 1 个占位符(是 1-3 位的数字)
// 例子:
// (new Date()).Format("yyyy-MM-dd hh:mm:ss.S") ==> 2006-07-02 08:09:04.423
// (new Date()).Format("yyyy-M-d h:m:s.S") ==> 2006-7-2 8:9:4.18
Date.prototype.Format = function (fmt) { //author: meizz
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;
}
【版权声明】本文内容来自摩杜云社区用户原创、第三方投稿、转载,内容版权归原作者所有。本网站的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@moduyun.com

上一篇: 7、磁盘和文件管理 下一篇: Java Socket Demo
  1. 分享:
最后一次编辑于 2023年11月14日 0

暂无评论

推荐阅读
  TEZNKK3IfmPf   2024年03月29日   74   0   0 标签js
  TEZNKK3IfmPf   2024年03月29日   20   0   0 js
  TEZNKK3IfmPf   2023年11月15日   27   0   0 ajaxjs
  TEZNKK3IfmPf   2023年11月15日   157   0   0 cssjshtml5
  TEZNKK3IfmPf   2023年11月15日   29   0   0 javajavascriptjs
  TEZNKK3IfmPf   2023年11月15日   56   0   0 htmljavajs
  TEZNKK3IfmPf   2023年11月15日   34   0   0 csshtmljs
  TEZNKK3IfmPf   2023年11月15日   28   0   0 csshtmljs
  TEZNKK3IfmPf   2023年11月15日   22   0   0 htmlvuejs
TEZNKK3IfmPf