博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
(转)JS Date格式化为yyyy-MM-dd类字符串
阅读量:4656 次
发布时间:2019-06-09

本文共 704 字,大约阅读时间需要 2 分钟。

Date.prototype.format = function(format)
{
 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;
}
 
日期格式化
var d = new Date();
d.format('yyyy-MM-dd');

转载于:https://www.cnblogs.com/laneyfu/p/5042022.html

你可能感兴趣的文章
Mac上编写C语言程序
查看>>
251.Flatten 2D Vector
查看>>
WLS Exception: Need to specify class name in environment or system property Solution
查看>>
人见人爱A^B
查看>>
消除头文件
查看>>
Android中数据文件解析(Json解析)
查看>>
自定义seekBar设置进度条背景图片
查看>>
java容器类1:Collection,List,ArrayList,LinkedList深入解读
查看>>
16日彻底去除安卓应用的内置广告
查看>>
再谈.NET Micro Framework移植
查看>>
ssm资源配置
查看>>
斗鱼爬虫,爬取颜值频道的主播图片和名字
查看>>
【Codeforces Round #439 (Div. 2) B】The Eternal Immortality
查看>>
【MemSQL Start[c]UP 3.0 - Round 1 B】 Lazy Security Guard
查看>>
【codeforces 499C】Crazy Town
查看>>
js 逻辑与 逻辑或
查看>>
“请求/响应”模型
查看>>
【坑】重写一个vector
查看>>
【UOJ 55】志愿者选拔
查看>>
Python -- pandas
查看>>